use of org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl in project activemq-artemis by apache.
the class ActiveMQSessionContext method createConsumer.
@Override
public ClientConsumerInternal createConsumer(SimpleString queueName, SimpleString filterString, int windowSize, int maxRate, int ackBatchSize, boolean browseOnly, Executor executor, Executor flowControlExecutor) throws ActiveMQException {
long consumerID = idGenerator.generateID();
ActiveMQConsumerContext consumerContext = new ActiveMQConsumerContext(consumerID);
SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(consumerID, queueName, filterString, browseOnly, true);
SessionQueueQueryResponseMessage queueInfo;
if (sessionChannel.getConnection().isVersionBeforeAddressChange()) {
queueInfo = (SessionQueueQueryResponseMessage) sessionChannel.sendBlocking(request, PacketImpl.SESS_QUEUEQUERY_RESP_V2);
} else {
queueInfo = (SessionQueueQueryResponseMessage) sessionChannel.sendBlocking(request, PacketImpl.SESS_QUEUEQUERY_RESP_V3);
}
return new ClientConsumerImpl(session, consumerContext, queueName, filterString, browseOnly, calcWindowSize(windowSize), ackBatchSize, maxRate > 0 ? new TokenBucketLimiterImpl(maxRate, false) : null, executor, flowControlExecutor, this, queueInfo.toQueueQuery(), lookupTCCL());
}
use of org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl in project activemq-artemis by apache.
the class ConsumerCloseTest method testCloseWithScheduledRedeliveryWithTX.
@Test
public void testCloseWithScheduledRedeliveryWithTX() throws Exception {
AddressSettings settings = new AddressSettings().setRedeliveryDelay(1000);
server.getAddressSettingsRepository().addMatch("#", settings);
ClientProducer producer = session.createProducer(address);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
message.putIntProperty("count", i);
producer.send(message);
}
session.close();
session = addClientSession(sf.createSession(false, false));
ClientConsumer consumer = session.createConsumer(queue);
session.start();
ClientMessage msg = consumer.receive(500);
msg.acknowledge();
long timeout = System.currentTimeMillis() + 1000;
while (((ClientConsumerImpl) consumer).getBufferSize() < 2 && System.currentTimeMillis() > timeout) {
Thread.sleep(10);
}
consumer.close();
session.rollback();
consumer = session.createConsumer(queue);
// We received one, so we must receive the others now
for (int i = 0; i < numMessages - 1; i++) {
msg = consumer.receive(1000);
assertNotNull("Expected message at i=" + i, msg);
msg.acknowledge();
}
assertNull(consumer.receiveImmediate());
// The first message received after redeliveryDelay
msg = consumer.receive(5000);
assertNotNull(msg);
assertEquals(0, msg.getIntProperty("count").intValue());
msg.acknowledge();
session.commit();
assertNull(consumer.receiveImmediate());
// Close shouldn't wait for all messages to be processed before closing
long start = System.currentTimeMillis();
consumer.close();
long end = System.currentTimeMillis();
Assert.assertTrue(end - start <= 1500);
}
use of org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl in project activemq-artemis by apache.
the class ConsumerCloseTest method testCloseWithManyMessagesInBufferAndSlowConsumer.
// https://jira.jboss.org/jira/browse/JBMESSAGING-1526
@Test
public void testCloseWithManyMessagesInBufferAndSlowConsumer() throws Exception {
ClientConsumer consumer = session.createConsumer(queue);
ClientProducer producer = session.createProducer(address);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
producer.send(message);
}
final CountDownLatch received = new CountDownLatch(1);
final CountDownLatch waitingToProceed = new CountDownLatch(1);
class MyHandler implements MessageHandler {
@Override
public void onMessage(final ClientMessage message) {
try {
received.countDown();
waitingToProceed.await();
} catch (Exception e) {
}
}
}
consumer.setMessageHandler(new MyHandler());
session.start();
assertTrue(received.await(5, TimeUnit.SECONDS));
long timeout = System.currentTimeMillis() + 1000;
// Instead of waiting a long time (like 1 second) we just make sure the buffer is full on the client
while (((ClientConsumerImpl) consumer).getBufferSize() < 2 && System.currentTimeMillis() > timeout) {
Thread.sleep(10);
}
waitingToProceed.countDown();
// Close shouldn't wait for all messages to be processed before closing
long start = System.currentTimeMillis();
consumer.close();
long end = System.currentTimeMillis();
Assert.assertTrue(end - start <= 1500);
}
use of org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl in project activemq-artemis by apache.
the class ConsumerCloseTest method testCloseWithScheduledRedelivery.
@Test
public void testCloseWithScheduledRedelivery() throws Exception {
AddressSettings settings = new AddressSettings().setRedeliveryDelay(50000);
server.getAddressSettingsRepository().addMatch("#", settings);
ClientConsumer consumer = session.createConsumer(queue);
ClientProducer producer = session.createProducer(address);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session.createMessage(false);
producer.send(message);
}
session.start();
ClientMessage msg = consumer.receive(5000);
msg.acknowledge();
long timeout = System.currentTimeMillis() + 1000;
while (((ClientConsumerImpl) consumer).getBufferSize() < 2 && System.currentTimeMillis() > timeout) {
Thread.sleep(10);
}
consumer.close();
consumer = session.createConsumer(queue);
// We received one, so we must receive the others now
for (int i = 0; i < numMessages - 1; i++) {
msg = consumer.receive(1000);
assertNotNull("Expected message at i=" + i, msg);
msg.acknowledge();
}
assertNull(consumer.receiveImmediate());
// Close shouldn't wait for all messages to be processed before closing
long start = System.currentTimeMillis();
consumer.close();
long end = System.currentTimeMillis();
Assert.assertTrue(end - start <= 1500);
}
use of org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl in project activemq-artemis by apache.
the class HornetQClientSessionContext method createConsumer.
@Override
public ClientConsumerInternal createConsumer(SimpleString queueName, SimpleString filterString, int windowSize, int maxRate, int ackBatchSize, boolean browseOnly, Executor executor, Executor flowControlExecutor) throws ActiveMQException {
long consumerID = idGenerator.generateID();
ActiveMQConsumerContext consumerContext = new ActiveMQConsumerContext(consumerID);
SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(consumerID, queueName, filterString, browseOnly, true);
SessionQueueQueryResponseMessage queueInfo = (SessionQueueQueryResponseMessage) getSessionChannel().sendBlocking(request, PacketImpl.SESS_QUEUEQUERY_RESP);
return new ClientConsumerImpl(session, consumerContext, queueName, filterString, browseOnly, calcWindowSize(windowSize), ackBatchSize, maxRate > 0 ? new TokenBucketLimiterImpl(maxRate, false) : null, executor, flowControlExecutor, this, queueInfo.toQueueQuery(), lookupTCCL());
}
Aggregations