Search in sources :

Example 6 with ServerConsumer

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

the class AMQPSessionCallback method cancel.

public void cancel(Object brokerConsumer, Message message, boolean updateCounts) throws Exception {
    OperationContext oldContext = recoverContext();
    try {
        ((ServerConsumer) brokerConsumer).individualCancel(message.getMessageID(), updateCounts);
        ((ServerConsumer) brokerConsumer).getQueue().forceDelivery();
    } finally {
        resetContext(oldContext);
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 7 with ServerConsumer

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

the class AMQPSessionCallback method createSender.

public Object createSender(ProtonServerSenderContext protonSender, SimpleString queue, String filter, boolean browserOnly) throws Exception {
    long consumerID = consumerIDGenerator.generateID();
    filter = SelectorTranslator.convertToActiveMQFilterString(filter);
    ServerConsumer consumer = serverSession.createConsumer(consumerID, queue, SimpleString.toSimpleString(filter), browserOnly, false, null);
    // AMQP handles its own flow control for when it's started
    consumer.setStarted(true);
    consumer.setProtocolContext(protonSender);
    return consumer;
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 8 with ServerConsumer

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

the class ProtonTransactionRefsOperation method rollbackRedelivery.

@Override
public void rollbackRedelivery(Transaction txn, MessageReference ref, long timeBase, Map<QueueImpl, LinkedList<MessageReference>> queueMap) throws Exception {
    ProtonTransactionImpl tx = (ProtonTransactionImpl) txn;
    if (tx.getDeliveries().containsKey(ref)) {
        Delivery del = tx.getDeliveries().get(ref).getA();
        ServerConsumer consumer = (ServerConsumer) tx.getDeliveries().get(ref).getB().getBrokerConsumer();
        // Rollback normally if the delivery is not settled or a forced TX rollback is done (e.g. connection drop).
        if (del.remotelySettled() || !tx.isDischarged()) {
            super.rollbackRedelivery(tx, ref, timeBase, queueMap);
        } else {
            ref.incrementDeliveryCount();
            consumer.backToDelivering(ref);
            del.disposition(del.getLocalState() == null ? del.getDefaultDeliveryState() : del.getLocalState());
        }
    } else {
        super.rollbackRedelivery(tx, ref, timeBase, queueMap);
    }
}
Also used : Delivery(org.apache.qpid.proton.engine.Delivery) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 9 with ServerConsumer

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

the class ActiveMQServerControlTest method testCloseJMSclient.

@Test
public void testCloseJMSclient() throws Exception {
    ActiveMQServerControl serverControl = createManagementControl();
    ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    Connection conn = cf.createConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Topic topic = ActiveMQJMSClient.createTopic("ConsumerTestTopic");
    MessageConsumer JMSclient = session.createConsumer(topic, "test1");
    long clientID = -1;
    String sessionID = ((ClientSessionImpl) (((ActiveMQSession) session).getCoreSession())).getName();
    Set<ServerSession> sessions = server.getSessions();
    for (ServerSession sess : sessions) {
        if (sess.getName().equals(sessionID.toString())) {
            Set<ServerConsumer> serverConsumers = sess.getServerConsumers();
            for (ServerConsumer serverConsumer : serverConsumers) {
                clientID = serverConsumer.sequentialID();
            }
        }
    }
    Assert.assertFalse(((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
    serverControl.closeConsumerWithID(sessionID, Long.toString(clientID));
    Wait.waitFor(() -> ((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
    Assert.assertTrue(((org.apache.activemq.artemis.jms.client.ActiveMQMessageConsumer) JMSclient).isClosed());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) Connection(javax.jms.Connection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSessionImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionImpl) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 10 with ServerConsumer

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

the class ServerSessionImpl method individualAcknowledge.

@Override
public void individualAcknowledge(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();
        consumer.individualAcknowledge(tx, messageID);
        newTX.rollback();
    } else {
        consumer.individualAcknowledge(autoCommitAcks ? null : tx, messageID);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

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