Search in sources :

Example 16 with ClientProducer

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

the class DeadLetterAddressTest method testBasicSend.

@Test
public void testBasicSend() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    SimpleString adName = new SimpleString("ad1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(adName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(adName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
    clientConsumer = clientSession.createConsumer(dlq);
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    assertEquals("q1", m.getStringProperty(Message.HDR_ORIGINAL_QUEUE));
    assertEquals("ad1", m.getStringProperty(Message.HDR_ORIGINAL_ADDRESS));
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
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 17 with ClientProducer

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

the class DeadLetterAddressTest method testDeadLetterAddressWithOverridenSublevelAddressSettings.

@Test
public void testDeadLetterAddressWithOverridenSublevelAddressSettings() throws Exception {
    int defaultDeliveryAttempt = 3;
    int specificeDeliveryAttempt = defaultDeliveryAttempt + 1;
    SimpleString address = new SimpleString("prefix.address");
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString defaultDeadLetterAddress = RandomUtil.randomSimpleString();
    SimpleString defaultDeadLetterQueue = RandomUtil.randomSimpleString();
    SimpleString specificDeadLetterAddress = RandomUtil.randomSimpleString();
    SimpleString specificDeadLetterQueue = RandomUtil.randomSimpleString();
    AddressSettings defaultAddressSettings = new AddressSettings().setMaxDeliveryAttempts(defaultDeliveryAttempt).setDeadLetterAddress(defaultDeadLetterAddress);
    server.getAddressSettingsRepository().addMatch("*", defaultAddressSettings);
    AddressSettings specificAddressSettings = new AddressSettings().setMaxDeliveryAttempts(specificeDeliveryAttempt).setDeadLetterAddress(specificDeadLetterAddress);
    server.getAddressSettingsRepository().addMatch(address.toString(), specificAddressSettings);
    clientSession.createQueue(address, queue, false);
    clientSession.createQueue(defaultDeadLetterAddress, defaultDeadLetterQueue, false);
    clientSession.createQueue(specificDeadLetterAddress, specificDeadLetterQueue, false);
    ClientProducer producer = clientSession.createProducer(address);
    ClientMessage clientMessage = createTextMessage(clientSession, "heyho!");
    producer.send(clientMessage);
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(queue);
    ClientConsumer defaultDeadLetterConsumer = clientSession.createConsumer(defaultDeadLetterQueue);
    ClientConsumer specificDeadLetterConsumer = clientSession.createConsumer(specificDeadLetterQueue);
    for (int i = 0; i < defaultDeliveryAttempt; i++) {
        ClientMessage m = clientConsumer.receive(500);
        Assert.assertNotNull(m);
        Assert.assertEquals(i + 1, m.getDeliveryCount());
        m.acknowledge();
        clientSession.rollback();
    }
    Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate());
    Assert.assertNull(specificDeadLetterConsumer.receiveImmediate());
    // one more redelivery attempt:
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(specificeDeliveryAttempt, m.getDeliveryCount());
    m.acknowledge();
    clientSession.rollback();
    Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate());
    Assert.assertNotNull(specificDeadLetterConsumer.receive(500));
}
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 18 with ClientProducer

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

the class DeadLetterAddressTest method testBasicSendWithDLAButNoBinding.

// HORNETQ- 1084
@Test
public void testBasicSendWithDLAButNoBinding() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    // SimpleString dlq = new SimpleString("DLQ1");
    // clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
    Queue q = (Queue) server.getPostOffice().getBinding(qName).getBindable();
    Assert.assertEquals(0, q.getDeliveringCount());
}
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) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 19 with ClientProducer

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

the class DeadLetterAddressTest method testBasicSendToNoQueue.

@Test
public void testBasicSendToNoQueue() throws Exception {
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
}
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 20 with ClientProducer

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

the class DurableQueueTest method testConsumeFromDurableQueueAfterServerRestart.

@Test
public void testConsumeFromDurableQueueAfterServerRestart() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, true);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(true));
    session.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    Assert.assertNotNull(message);
    message.acknowledge();
    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