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);
}
});
}
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();
}
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()));
}
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);
}
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);
}
Aggregations