Search in sources :

Example 16 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer 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 17 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer 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 18 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer 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)

Example 19 with ClientConsumer

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

the class ExpiryAddressTest method testBasicSendToNoQueue.

@Test
public void testBasicSendToNoQueue() throws Exception {
    SimpleString ea = new SimpleString("EA");
    SimpleString qName = new SimpleString("q1");
    SimpleString eq = new SimpleString("EQ1");
    SimpleString eq2 = new SimpleString("EQ2");
    clientSession.createQueue(ea, eq, null, false);
    clientSession.createQueue(ea, eq2, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    ClientMessage clientMessage = createTextMessage(clientSession, "heyho!");
    clientMessage.setExpiration(System.currentTimeMillis());
    producer.send(clientMessage);
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
}
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)

Example 20 with ClientConsumer

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

the class ExpiryAddressTest method testHeadersSet.

@Test
public void testHeadersSet() throws Exception {
    final int NUM_MESSAGES = 5;
    SimpleString ea = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    SimpleString eq = new SimpleString("EA1");
    clientSession.createQueue(ea, eq, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ServerLocator locator1 = createInVMNonHALocator();
    ClientSessionFactory sessionFactory = createSessionFactory(locator1);
    ClientSession sendSession = sessionFactory.createSession(false, true, true);
    ClientProducer producer = sendSession.createProducer(qName);
    long expiration = System.currentTimeMillis();
    for (int i = 0; i < NUM_MESSAGES; i++) {
        ClientMessage tm = createTextMessage(clientSession, "Message:" + i);
        tm.setExpiration(expiration);
        producer.send(tm);
    }
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    clientSession.start();
    ClientMessage m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    // All the messages should now be in the EQ
    ClientConsumer cc3 = clientSession.createConsumer(eq);
    for (int i = 0; i < NUM_MESSAGES; i++) {
        ClientMessage tm = cc3.receive(1000);
        Assert.assertNotNull(tm);
        String text = tm.getBodyBuffer().readString();
        Assert.assertEquals("Message:" + i, text);
        // Check the headers
        Long actualExpiryTime = (Long) tm.getObjectProperty(Message.HDR_ACTUAL_EXPIRY_TIME);
        Assert.assertTrue(actualExpiryTime >= expiration);
    }
    sendSession.close();
    locator1.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)720 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)642 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)624 Test (org.junit.Test)584 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)569 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)409 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)348 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)154 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)132 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)88 Configuration (org.apache.activemq.artemis.core.config.Configuration)81 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)79 CountDownLatch (java.util.concurrent.CountDownLatch)72 Queue (org.apache.activemq.artemis.core.server.Queue)63 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)62 Xid (javax.transaction.xa.Xid)55 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)52 HashMap (java.util.HashMap)48 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)46 ArrayList (java.util.ArrayList)44