Search in sources :

Example 21 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings 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 22 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings 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)

Example 23 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ExpiryAddressTest method testExpireWithDefaultAddressSettings.

@Test
public void testExpireWithDefaultAddressSettings() throws Exception {
    SimpleString ea = new SimpleString("EA");
    SimpleString qName = new SimpleString("q1");
    SimpleString eq = new SimpleString("EA1");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea);
    server.getAddressSettingsRepository().setDefault(addressSettings);
    clientSession.createQueue(ea, eq, 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();
    clientConsumer = clientSession.createConsumer(eq);
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    m.acknowledge();
}
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 24 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ExpiryAddressTest method testExpireWithWildcardAddressSettings.

@Test
public void testExpireWithWildcardAddressSettings() throws Exception {
    SimpleString ea = new SimpleString("EA");
    SimpleString qName = new SimpleString("q1");
    SimpleString eq = new SimpleString("EA1");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea);
    server.getAddressSettingsRepository().addMatch("*", addressSettings);
    clientSession.createQueue(ea, eq, 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();
    clientConsumer = clientSession.createConsumer(eq);
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    m.acknowledge();
}
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 25 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings 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)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14