Search in sources :

Example 31 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class ActiveMQServerControlTest method testCloseCOREclient.

@Test
public void testCloseCOREclient() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    boolean durable = true;
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createAddress(address.toString(), "ANYCAST");
    serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, durable, -1, false, false);
    ServerLocator receiveLocator = createInVMNonHALocator();
    ClientSessionFactory receiveCsf = createSessionFactory(receiveLocator);
    ClientSession receiveClientSession = receiveCsf.createSession(true, false, false);
    final ClientConsumer COREclient = receiveClientSession.createConsumer(name);
    ServerSession ss = server.getSessions().iterator().next();
    ServerConsumer sc = ss.getServerConsumers().iterator().next();
    Assert.assertFalse(COREclient.isClosed());
    serverControl.closeConsumerWithID(((ClientSessionImpl) receiveClientSession).getName(), Long.toString(sc.sequentialID()));
    Wait.waitFor(() -> COREclient.isClosed());
    Assert.assertTrue(COREclient.isClosed());
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 32 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class SessionMetadataAddExceptionTest method createDefaultConfig.

@Override
protected Configuration createDefaultConfig(boolean netty) throws Exception {
    Configuration config = super.createDefaultConfig(netty);
    config.registerBrokerPlugin(new ActiveMQServerPlugin() {

        @Override
        public void beforeSessionMetadataAdded(ServerSession session, String key, String data) throws ActiveMQException {
            if (ClientSession.JMS_SESSION_CLIENT_ID_PROPERTY.equals(key)) {
                if ("invalid".equals(data)) {
                    throw new ActiveMQException("Invalid clientId");
                }
            }
        }
    });
    return config;
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQServerPlugin(org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin)

Aggregations

ServerSession (org.apache.activemq.artemis.core.server.ServerSession)32 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)11 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)7 HashSet (java.util.HashSet)6 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 Test (org.junit.Test)5 Date (java.util.Date)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4 JsonObjectBuilder (javax.json.JsonObjectBuilder)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)4 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 LinkedList (java.util.LinkedList)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2