Search in sources :

Example 21 with ServerConsumer

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

the class ServerSessionImpl method setStarted.

private void setStarted(final boolean s) {
    Set<ServerConsumer> consumersClone = new HashSet<>(consumers.values());
    for (ServerConsumer consumer : consumersClone) {
        consumer.setStarted(s);
    }
    started = s;
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) HashSet(java.util.HashSet)

Example 22 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer 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 23 with ServerConsumer

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

the class ServerSessionImpl method acknowledge.

@Override
public void acknowledge(final long consumerID, final long messageID) throws Exception {
    ServerConsumer consumer = findConsumer(consumerID);
    if (tx != null && tx.getState() == State.ROLLEDBACK) {
        // JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just
        // have these messages to be stuck on the limbo until the server is restarted
        // The tx has already timed out, so we need to ack and rollback immediately
        Transaction newTX = newTransaction();
        try {
            consumer.acknowledge(newTX, messageID);
        } catch (Exception e) {
            // just ignored
            // will log it just in case
            logger.debug("Ignored exception while acking messageID " + messageID + " on a rolledback TX", e);
        }
        newTX.rollback();
    } else {
        consumer.acknowledge(autoCommitAcks ? null : tx, messageID);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) 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)

Example 24 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer 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 25 with ServerConsumer

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

the class AMQPSessionCallback method closeSender.

public void closeSender(final Object brokerConsumer) throws Exception {
    final ServerConsumer consumer = ((ServerConsumer) brokerConsumer);
    final CountDownLatch latch = new CountDownLatch(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                consumer.close(false);
                latch.countDown();
            } catch (Exception e) {
            }
        }
    };
    // Due to the nature of proton this could be happening within flushes from the queue-delivery (depending on how it happened on the protocol)
    // to avoid deadlocks the close has to be done outside of the main thread on an executor
    // otherwise you could get a deadlock
    Executor executor = protonSPI.getExeuctor();
    if (executor != null) {
        executor.execute(runnable);
    } else {
        runnable.run();
    }
    try {
        // a short timeout will do.. 1 second is already long enough
        if (!latch.await(1, TimeUnit.SECONDS)) {
            logger.debug("Could not close consumer on time");
        }
    } catch (InterruptedException e) {
        throw new ActiveMQAMQPInternalErrorException("Unable to close consumers for queue: " + consumer.getQueue());
    }
    consumer.getQueue().recheckRefCount(serverSession.getSessionContext());
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Executor(java.util.concurrent.Executor) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)

Aggregations

ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)26 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)4 HashSet (java.util.HashSet)3 JsonArrayBuilder (javax.json.JsonArrayBuilder)3 XAException (javax.transaction.xa.XAException)3 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)3 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)3 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 Test (org.junit.Test)3 JsonObject (javax.json.JsonObject)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 Binding (org.apache.activemq.artemis.core.postoffice.Binding)2