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);
}
}
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;
}
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);
}
}
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());
}
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);
}
}
Aggregations