use of org.apache.activemq.artemis.api.core.client.ClientMessage 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);
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
}
Aggregations