Search in sources :

Example 66 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.

the class OptimizedAckTest method testReceivedMessageNotInFlightAfterScheduledAckFires.

public void testReceivedMessageNotInFlightAfterScheduledAckFires() throws Exception {
    connection.setOptimizedAckScheduledAckInterval(TimeUnit.SECONDS.toMillis(10));
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
    assertTrue("After delay the scheduled ack should ack all inflight.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("inflight count: " + coreQueue.getDeliveringCount());
            return 0 == coreQueue.getDeliveringCount();
        }
    }));
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Example 67 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.

the class OptimizedAckTest method testReceivedMessageStillInflight.

public void testReceivedMessageStillInflight() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    // check queue delivering count is 10
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("delivering count is 10", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Example 68 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.

the class OptimizedAckTest method testVerySlowReceivedMessageStillInflight.

public void testVerySlowReceivedMessageStillInflight() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    // check queue delivering count is 10
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        Thread.sleep(400);
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        Thread.sleep(400);
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) MessageConsumer(javax.jms.MessageConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Session(javax.jms.Session)

Example 69 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.

the class DirectDeliverTest method testDirectDeliver.

@Test
public void testDirectDeliver() throws Exception {
    final String foo = "foo";
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession();
    session.createQueue(foo, RoutingType.ANYCAST, foo);
    Binding binding = server.getPostOffice().getBinding(new SimpleString(foo));
    Queue queue = (Queue) binding.getBindable();
    assertTrue(queue.isDirectDeliver());
    ClientProducer prod = session.createProducer(foo);
    ClientConsumer cons = session.createConsumer(foo);
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage msg = session.createMessage(true);
        prod.send(msg);
    }
    queue.flushExecutor();
    // Consumer is not started so should go queued
    assertFalse(queue.isDirectDeliver());
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage msg = cons.receive(10000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    Thread.sleep((long) (QueueImpl.CHECK_QUEUE_SIZE_PERIOD * 1.5));
    // Add another message, should go direct
    ClientMessage msg = session.createMessage(true);
    prod.send(msg);
    queue.flushExecutor();
    assertTrue(queue.isDirectDeliver());
    // Send some more
    for (int i = 0; i < numMessages; i++) {
        msg = session.createMessage(true);
        prod.send(msg);
    }
    for (int i = 0; i < numMessages + 1; i++) {
        msg = cons.receive(10000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    assertTrue(queue.isDirectDeliver());
    session.stop();
    for (int i = 0; i < numMessages; i++) {
        msg = session.createMessage(true);
        prod.send(msg);
    }
    assertFalse(queue.isDirectDeliver());
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 70 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.

the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecuritySucceeds.

@Test
public void testSimpleMessageReceivedOnQueueWithSecuritySucceeds() throws Exception {
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addRole("testuser", "arole");
    Role role = new Role("arole", false, true, false, false, false, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setUser("testuser");
    spec.setPassword("testpassword");
    spec.setSetupAttempts(0);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Binding (org.apache.activemq.artemis.core.postoffice.Binding)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)52 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)29 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)28 Test (org.junit.Test)25 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)24 Queue (org.apache.activemq.artemis.core.server.Queue)24 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)18 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)17 ArrayList (java.util.ArrayList)12 Filter (org.apache.activemq.artemis.core.filter.Filter)10 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)9 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)7 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7