Search in sources :

Example 46 with Binding

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

the class ActiveMQMessageHandlerTest method testEndpointDeactivated.

@Test
public void testEndpointDeactivated() throws Exception {
    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);
    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);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 0);
    assertTrue(endpoint.released);
    qResourceAdapter.stop();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 47 with Binding

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

the class JournalPendingMessageTest method getQueues.

protected List<Queue> getQueues(final String address) throws Exception {
    final List<Queue> queues = new ArrayList<>();
    for (Binding binding : server.getPostOffice().getDirectBindings(SimpleString.toSimpleString(address)).getBindings()) {
        if (binding.getType() == BindingType.LOCAL_QUEUE) {
            LocalQueueBinding queueBinding = (LocalQueueBinding) binding;
            queues.add(queueBinding.getQueue());
        }
    }
    return queues;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ArrayList(java.util.ArrayList) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 48 with Binding

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

the class MessageRedistributionTest method getRemoteQueueBinding.

private RemoteQueueBinding getRemoteQueueBinding(ActiveMQServer server) throws Exception {
    ActiveMQServer remoteServer = server;
    Bindings bindings = remoteServer.getPostOffice().getBindingsForAddress(new SimpleString("queues.testaddress"));
    Collection<Binding> bindingSet = bindings.getBindings();
    return getRemoteQueueBinding(bindingSet);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 49 with Binding

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

the class ActiveMQMessageHandlerXATest method testXACommitWhenStopping.

@Test
public void testXACommitWhenStopping() throws Exception {
    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.setMaxSession(1);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch beforeDeliveryLatch = new CountDownLatch(1);
    PausingXADummyEndpoint endpoint = new PausingXADummyEndpoint(latch, beforeDeliveryLatch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    ClientMessage message2 = session.createMessage(true);
    message2.getBodyBuffer().writeString("teststring2");
    clientProducer.send(message2);
    session.close();
    beforeDeliveryLatch.await(5, TimeUnit.SECONDS);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertFalse(endpoint.interrupted);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    long messageCount = getMessageCount((Queue) binding.getBindable());
    assertEquals(1, messageCount);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 50 with Binding

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

the class ActiveMQMessageHandlerXATest method testXACommitInterruptsWhenStopping.

@Test
public void testXACommitInterruptsWhenStopping() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setCallTimeout(500L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setMaxSession(1);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch beforeDeliveryLatch = new CountDownLatch(1);
    PausingXADummyEndpoint endpoint = new PausingXADummyEndpoint(latch, beforeDeliveryLatch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    ClientMessage message2 = session.createMessage(true);
    message2.getBodyBuffer().writeString("teststring2");
    clientProducer.send(message2);
    session.close();
    beforeDeliveryLatch.await(5, TimeUnit.SECONDS);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertTrue(endpoint.interrupted);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    Wait.waitFor(() -> getMessageCount((Queue) binding.getBindable()) == 1);
    long messageCount = getMessageCount((Queue) binding.getBindable());
    assertEquals(1, messageCount);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) 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