Search in sources :

Example 81 with ClientProducer

use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.

the class MessageDurabilityTest method testDurableMessageOnNonDurableQueue.

/**
 * we can send a durable msg to a non durable queue but the msg won't be persisted
 */
@Test
public void testDurableMessageOnNonDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    final SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, !durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    restart();
    session.start();
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(queue);
        }
    });
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 82 with ClientProducer

use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.

the class MessageGroupingConnectionFactoryTest method doTestBasicGroupingUsingConnectionFactory.

private void doTestBasicGroupingUsingConnectionFactory() throws Exception {
    ClientProducer clientProducer = clientSession.createProducer(qName);
    ClientConsumer consumer = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);
    clientSession.start();
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(clientSession, "m" + i);
        clientProducer.send(message);
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
    consumer.setMessageHandler(dummyMessageHandler);
    DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
    consumer2.setMessageHandler(dummyMessageHandler2);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    Assert.assertEquals(100, dummyMessageHandler.list.size());
    Assert.assertEquals(0, dummyMessageHandler2.list.size());
    consumer.close();
    consumer2.close();
}
Also used : 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)

Example 83 with ClientProducer

use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.

the class MessageCounterTest method testMessageCounter.

@Test
public void testMessageCounter() throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(null, null, false, false, false, false, 0);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(session, "m" + i);
        producer.send(message);
    }
    session.commit();
    session.start();
    Assert.assertEquals(100, getMessageCount(server.getPostOffice(), QUEUE.toString()));
    ClientConsumer consumer = session.createConsumer(QUEUE, null, false);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer.receive(1000);
        Assert.assertNotNull(message);
        message.acknowledge();
        session.commit();
        Assert.assertEquals("m" + i, message.getBodyBuffer().readString());
    }
    session.close();
    Assert.assertEquals(0, getMessageCount(server.getPostOffice(), QUEUE.toString()));
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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 84 with ClientProducer

use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.

the class MessageExpirationTest method testMessageExpiredWithExpiryAddress.

@Test
public void testMessageExpiredWithExpiryAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    final SimpleString expiryAddress = RandomUtil.randomSimpleString();
    SimpleString expiryQueue = RandomUtil.randomSimpleString();
    server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() {

        private static final long serialVersionUID = -6476053400596299130L;

        @Override
        public SimpleString getExpiryAddress() {
            return expiryAddress;
        }
    });
    session.createQueue(address, queue, false);
    session.createQueue(expiryAddress, expiryQueue, false);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(false);
    message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
    producer.send(message);
    Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    ClientConsumer expiryConsumer = session.createConsumer(expiryQueue);
    ClientMessage expiredMessage = expiryConsumer.receive(500);
    Assert.assertNotNull(expiredMessage);
    Assert.assertNotNull(expiredMessage.getObjectProperty(Message.HDR_ACTUAL_EXPIRY_TIME));
    Assert.assertEquals(address, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_ADDRESS));
    Assert.assertEquals(queue, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_QUEUE));
    consumer.close();
    expiryConsumer.close();
    session.deleteQueue(queue);
    session.deleteQueue(expiryQueue);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 85 with ClientProducer

use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.

the class MessageExpirationTest method testMessageExpiredWithoutExpiryAddress.

@Test
public void testMessageExpiredWithoutExpiryAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, false);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(false);
    message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
    producer.send(message);
    Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    consumer.close();
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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)

Aggregations

ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)859 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)716 Test (org.junit.Test)702 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)658 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)644 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)478 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)395 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)173 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)166 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)106 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)103 CountDownLatch (java.util.concurrent.CountDownLatch)102 Configuration (org.apache.activemq.artemis.core.config.Configuration)93 Queue (org.apache.activemq.artemis.core.server.Queue)85 Xid (javax.transaction.xa.Xid)70 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)64 HashMap (java.util.HashMap)63 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)55 ArrayList (java.util.ArrayList)51 QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)50