Search in sources :

Example 76 with Binding

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

the class ServerSessionImpl method createConsumer.

@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
    final SimpleString unPrefixedQueueName = removePrefix(queueName);
    Binding binding = postOffice.getBinding(unPrefixedQueueName);
    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
    }
    SimpleString address = removePrefix(binding.getAddress());
    if (browseOnly) {
        try {
            securityCheck(address, queueName, CheckType.BROWSE, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
        }
    } else {
        try {
            securityCheck(address, queueName, CheckType.CONSUME, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
        }
    }
    Filter filter = FilterImpl.createFilter(filterString);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
    }
    ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
    consumers.put(consumer.getID(), consumer);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
    }
    if (!browseOnly) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        Queue theQueue = (Queue) binding.getBindable();
        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
        // HORNETQ-946
        props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
        props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
        props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
        if (filterString != null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }
        Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
        if (logger.isDebugEnabled()) {
            logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
        }
        managementService.sendNotification(notification);
    }
    return consumer;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 77 with Binding

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

the class ActiveMQServerImpl method queueQuery.

@Override
public QueueQueryResult queueQuery(SimpleString name) {
    if (name == null) {
        throw ActiveMQMessageBundle.BUNDLE.queueNameIsNull();
    }
    boolean autoCreateQueues = getAddressSettingsRepository().getMatch(name.toString()).isAutoCreateQueues();
    boolean defaultPurgeOnNoConsumers = getAddressSettingsRepository().getMatch(name.toString()).isDefaultPurgeOnNoConsumers();
    int defaultMaxConsumers = getAddressSettingsRepository().getMatch(name.toString()).getDefaultMaxConsumers();
    boolean defaultExclusiveQueue = getAddressSettingsRepository().getMatch(name.toString()).isDefaultExclusiveQueue();
    boolean defaultLastValueQueue = getAddressSettingsRepository().getMatch(name.toString()).isDefaultLastValueQueue();
    QueueQueryResult response;
    Binding binding = getPostOffice().getBinding(name);
    SimpleString managementAddress = getManagementService() != null ? getManagementService().getManagementAddress() : null;
    if (binding != null && binding.getType() == BindingType.LOCAL_QUEUE) {
        Queue queue = (Queue) binding.getBindable();
        Filter filter = queue.getFilter();
        SimpleString filterString = filter == null ? null : filter.getFilterString();
        response = new QueueQueryResult(name, binding.getAddress(), queue.isDurable(), queue.isTemporary(), filterString, queue.getConsumerCount(), queue.getMessageCount(), autoCreateQueues, true, queue.isAutoCreated(), queue.isPurgeOnNoConsumers(), queue.getRoutingType(), queue.getMaxConsumers(), queue.isExclusive(), queue.isLastValue());
    } else if (name.equals(managementAddress)) {
        // make an exception for the management address (see HORNETQ-29)
        response = new QueueQueryResult(name, managementAddress, true, false, null, -1, -1, autoCreateQueues, true, false, false, RoutingType.MULTICAST, -1, false, false);
    } else if (autoCreateQueues) {
        response = new QueueQueryResult(name, name, true, false, null, 0, 0, true, false, false, defaultPurgeOnNoConsumers, RoutingType.MULTICAST, defaultMaxConsumers, defaultExclusiveQueue, defaultLastValueQueue);
    } else {
        response = new QueueQueryResult(null, null, false, false, null, 0, 0, false, false, false, false, RoutingType.MULTICAST, 0, null, null);
    }
    return response;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SynchronousQueue(java.util.concurrent.SynchronousQueue) Queue(org.apache.activemq.artemis.core.server.Queue) ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint)

Example 78 with Binding

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

the class ActiveMQServerImpl method locateQueue.

@Override
public Queue locateQueue(SimpleString queueName) {
    Binding binding = postOffice.getBinding(queueName);
    if (binding == null) {
        return null;
    }
    Bindable queue = binding.getBindable();
    if (!(queue instanceof Queue)) {
        throw new IllegalStateException("locateQueue should only be used to locate queues");
    }
    return (Queue) binding.getBindable();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Bindable(org.apache.activemq.artemis.core.server.Bindable) SynchronousQueue(java.util.concurrent.SynchronousQueue) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 79 with Binding

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

the class FQQNOpenWireTest method testTopic.

@Test
public // however we can test query functionality
void testTopic() throws Exception {
    Connection connection = factory.createConnection();
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(multicastAddress.toString());
        MessageConsumer consumer1 = session.createConsumer(topic);
        MessageConsumer consumer2 = session.createConsumer(topic);
        MessageConsumer consumer3 = session.createConsumer(topic);
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createMessage());
        // each consumer receives one
        Message m = consumer1.receive(2000);
        assertNotNull(m);
        m = consumer2.receive(2000);
        assertNotNull(m);
        m = consumer3.receive(2000);
        assertNotNull(m);
        Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
        for (Binding b : bindings.getBindings()) {
            System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
            SimpleString qName = b.getUniqueName();
            // do FQQN query
            QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
            assertTrue(result.isExists());
            assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
            // do qname query
            result = server.queueQuery(qName);
            assertTrue(result.isExists());
            assertEquals(result.getName(), qName);
        }
    } finally {
        connection.close();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Topic(javax.jms.Topic) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 80 with Binding

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

the class PagingOrderTest method testPageCounter.

@Test
public void testPageCounter() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
    Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    final AtomicInteger errors = new AtomicInteger(0);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            try {
                ServerLocator sl = createInVMNonHALocator();
                ClientSessionFactory sf = sl.createSessionFactory();
                ClientSession sess = sf.createSession(true, true, 0);
                sess.start();
                ClientConsumer cons = sess.createConsumer(ADDRESS);
                for (int i = 0; i < numberOfMessages; i++) {
                    ClientMessage msg = cons.receive(5000);
                    assertNotNull(msg);
                    assertEquals(i, msg.getIntProperty("id").intValue());
                    msg.acknowledge();
                }
                assertNull(cons.receiveImmediate());
                sess.close();
                sl.close();
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    t1.start();
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 20 == 0) {
            session.commit();
        }
    }
    session.commit();
    t1.join();
    assertEquals(0, errors.get());
    assertEquals(numberOfMessages, getMessageCount(q2));
    assertEquals(numberOfMessages, getMessagesAdded(q2));
    assertEquals(0, getMessageCount(q1));
    assertEquals(numberOfMessages, getMessagesAdded(q1));
    session.close();
    sf.close();
    locator.close();
    server.stop();
    server.start();
    Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
    q1 = null;
    q2 = null;
    for (Binding bind : bindings.getBindings()) {
        if (bind instanceof LocalQueueBinding) {
            LocalQueueBinding qb = (LocalQueueBinding) bind;
            if (qb.getQueue().getName().equals(ADDRESS)) {
                q1 = qb.getQueue();
            }
            if (qb.getQueue().getName().equals(new SimpleString("inactive"))) {
                q2 = qb.getQueue();
            }
        }
    }
    assertNotNull(q1);
    assertNotNull(q2);
    assertEquals("q2 msg count", numberOfMessages, getMessageCount(q2));
    assertEquals("q2 msgs added", numberOfMessages, getMessagesAdded(q2));
    assertEquals("q1 msg count", 0, getMessageCount(q1));
    // 0, since nothing was sent to the queue after the server was restarted
    assertEquals("q1 msgs added", 0, getMessagesAdded(q1));
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) 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