Search in sources :

Example 1 with BindingsImpl

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

the class TopicCleanupTest method testWildcardSubscriber.

@Test
public void testWildcardSubscriber() throws Exception {
    ActiveMQTopic topic = (ActiveMQTopic) createTopic("topic.A");
    Connection conn = cf.createConnection();
    conn.start();
    try {
        Session consumerStarSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerStar = consumerStarSession.createConsumer(ActiveMQJMSClient.createTopic("topic.*"));
        Session consumerASession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerA = consumerASession.createConsumer(topic);
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producerA = producerSession.createProducer(topic);
        TextMessage msg1 = producerSession.createTextMessage("text");
        producerA.send(msg1);
        consumerStar.close();
        consumerA.close();
        producerA.send(msg1);
        conn.close();
        boolean foundStrayRoutingBinding = false;
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(topic.getAddress()));
        Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap();
        for (SimpleString key : routingNames.keySet()) {
            if (!key.toString().equals(topic.getAddress())) {
                foundStrayRoutingBinding = true;
                assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
            }
        }
        assertFalse(foundStrayRoutingBinding);
    } finally {
        jmsServer.stop();
        jmsServer.start();
        try {
            conn.close();
        } catch (Throwable igonred) {
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) List(java.util.List) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with BindingsImpl

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

the class BindingsImplTest method internalTest.

private void internalTest(final boolean route) throws Exception {
    final FakeBinding fake = new FakeBinding(new SimpleString("a"));
    final Bindings bind = new BindingsImpl(null, null, null);
    bind.addBinding(fake);
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                bind.removeBinding(fake);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    Queue queue = new FakeQueue(new SimpleString("a"));
    t.start();
    for (int i = 0; i < 100; i++) {
        if (route) {
            bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
        } else {
            bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
        }
    }
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)2 BindingsImpl (org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl)2 List (java.util.List)1 Connection (javax.jms.Connection)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)1 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)1 Queue (org.apache.activemq.artemis.core.server.Queue)1 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)1 ActiveMQTopic (org.apache.activemq.artemis.jms.client.ActiveMQTopic)1 Test (org.junit.Test)1