Search in sources :

Example 1 with ClientConsumerImpl

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());
}
Also used : ClientConsumerImpl(org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl) SessionQueueQueryResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage) TokenBucketLimiterImpl(org.apache.activemq.artemis.utils.TokenBucketLimiterImpl) SessionCreateConsumerMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionCreateConsumerMessage)

Example 2 with ClientConsumerImpl

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);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientConsumerImpl(org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 3 with ClientConsumerImpl

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);
}
Also used : ClientConsumerImpl(org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl) MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 4 with ClientConsumerImpl

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);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientConsumerImpl(org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 5 with ClientConsumerImpl

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());
}
Also used : ClientConsumerImpl(org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl) ActiveMQConsumerContext(org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQConsumerContext) SessionQueueQueryResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage) TokenBucketLimiterImpl(org.apache.activemq.artemis.utils.TokenBucketLimiterImpl) SessionCreateConsumerMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionCreateConsumerMessage)

Aggregations

ClientConsumerImpl (org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl)5 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 Test (org.junit.Test)3 SessionCreateConsumerMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionCreateConsumerMessage)2 SessionQueueQueryResponseMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionQueueQueryResponseMessage)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 TokenBucketLimiterImpl (org.apache.activemq.artemis.utils.TokenBucketLimiterImpl)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 MessageHandler (org.apache.activemq.artemis.api.core.client.MessageHandler)1 ActiveMQConsumerContext (org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQConsumerContext)1