use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetScheduledCount.
@Test
public void testGetScheduledCount() throws Exception {
long delay = 500;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(0, queueControl.getScheduledCount());
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(durable);
message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + delay);
producer.send(message);
long timeout = System.currentTimeMillis() + 5000;
while (timeout > System.currentTimeMillis() && queueControl.getScheduledCount() != 1) {
Thread.sleep(100);
}
assertScheduledMetrics(queueControl, 1, durable);
assertMessageMetrics(queueControl, 1, durable);
consumeMessages(0, session, queue);
Thread.sleep(delay * 2);
Assert.assertEquals(0, queueControl.getScheduledCount());
consumeMessages(1, session, queue);
assertMessageMetrics(queueControl, 0, durable);
assertScheduledMetrics(queueControl, 0, durable);
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testSendMessageToDeadLetterAddress.
@Test
public void testSendMessageToDeadLetterAddress() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString deadLetterAddress = RandomUtil.randomSimpleString();
SimpleString deadLetterQueue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
session.createQueue(deadLetterAddress, RoutingType.MULTICAST, deadLetterQueue, null, durable);
ClientProducer producer = session.createProducer(address);
// send 2 messages on queue
producer.send(session.createMessage(durable));
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
QueueControl deadLetterQueueControl = createManagementControl(deadLetterAddress, deadLetterQueue);
assertMessageMetrics(queueControl, 2, durable);
// the message IDs are set on the server
Map<String, Object>[] messages = queueControl.listMessages(null);
Assert.assertEquals(2, messages.length);
long messageID = (Long) messages[0].get("messageID");
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(deadLetterAddress);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
Assert.assertEquals(0, getMessageCount(deadLetterQueueControl));
boolean movedToDeadLetterAddress = queueControl.sendMessageToDeadLetterAddress(messageID);
Assert.assertTrue(movedToDeadLetterAddress);
assertMessageMetrics(queueControl, 1, durable);
Thread.sleep(200);
assertMessageMetrics(deadLetterQueueControl, 1, durable);
// check there is a single message to consume from queue
consumeMessages(1, session, queue);
// check there is a single message to consume from deadletter queue
consumeMessages(1, session, deadLetterQueue);
session.deleteQueue(queue);
session.deleteQueue(deadLetterQueue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRemoveMessage2.
@Test
public void testRemoveMessage2() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
for (int i = 0; i < 100; i++) {
ClientMessage msg = session.createMessage(durable);
msg.putIntProperty("count", i);
producer.send(msg);
}
ClientConsumer cons = session.createConsumer(queue);
session.start();
LinkedList<ClientMessage> msgs = new LinkedList<>();
for (int i = 0; i < 50; i++) {
ClientMessage msg = cons.receive(1000);
msgs.add(msg);
}
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 100, durable);
// the message IDs are set on the server
Map<String, Object>[] messages = queueControl.listMessages(null);
Assert.assertEquals(50, messages.length);
int i = Integer.parseInt((messages[0].get("count")).toString());
assertEquals(50, i);
long messageID = (Long) messages[0].get("messageID");
// delete 1st message
boolean deleted = queueControl.removeMessage(messageID);
Assert.assertTrue(deleted);
assertMessageMetrics(queueControl, 99, durable);
cons.close();
// check there is a single message to consume from queue
consumeMessages(99, session, queue);
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListDeliveringMessages.
@Test
public void testListDeliveringMessages() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
int intValue = RandomUtil.randomInt();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
Queue srvqueue = server.locateQueue(queue);
QueueControl queueControl = createManagementControl(address, queue);
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(durable);
message.putIntProperty(new SimpleString("key"), intValue);
producer.send(message);
producer.send(session.createMessage(durable));
ClientConsumer consumer = session.createConsumer(queue);
session.start();
ClientMessage msgRec = consumer.receive(5000);
assertNotNull(msgRec);
assertEquals(msgRec.getIntProperty("key").intValue(), intValue);
ClientSessionFactory sf2 = createSessionFactory(locator);
ClientSession session2 = sf2.createSession(false, true, false);
ClientConsumer consumer2 = session2.createConsumer(queue);
session2.start();
ClientMessage msgRec2 = consumer2.receive(5000);
assertNotNull(msgRec2);
assertEquals(2, srvqueue.getDeliveringCount());
assertEquals(2, srvqueue.getConsumerCount());
System.out.println(queueControl.listDeliveringMessagesAsJSON());
Map<String, Map<String, Object>[]> deliveringMap = queueControl.listDeliveringMessages();
assertEquals(2, deliveringMap.size());
consumer.close();
consumer2.close();
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRetryMultipleMessages.
/**
* Test retry multiple messages from DLQ to original queue.
*/
@Test
public void testRetryMultipleMessages() throws Exception {
final SimpleString dla = new SimpleString("DLA");
final SimpleString qName = new SimpleString("q1");
final SimpleString adName = new SimpleString("ad1");
final SimpleString dlq = new SimpleString("DLQ1");
final String sampleText = "Put me on DLQ";
final int numMessagesToTest = 10;
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
session.createQueue(adName, RoutingType.MULTICAST, qName, null, durable);
// Send message to queue.
ClientProducer producer = session.createProducer(adName);
for (int i = 0; i < numMessagesToTest; i++) {
producer.send(createTextMessage(session, sampleText));
}
session.start();
final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(qName);
Queue q = binding.getQueue();
final LocalQueueBinding binding2 = (LocalQueueBinding) server.getPostOffice().getBinding(dlq);
Queue q2 = binding2.getQueue();
Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
queueMemorySizeField.setAccessible(true);
// Get memory size counters to verify
AtomicInteger queueMemorySize1 = (AtomicInteger) queueMemorySizeField.get(q);
AtomicInteger queueMemorySize2 = (AtomicInteger) queueMemorySizeField.get(q2);
// Verify that original queue has a memory size greater than 0 and DLQ is 0
assertTrue(queueMemorySize1.get() > 0);
assertTrue(queueMemorySize2.get() == 0);
// Read and rollback all messages to DLQ
ClientConsumer clientConsumer = session.createConsumer(qName);
for (int i = 0; i < numMessagesToTest; i++) {
ClientMessage clientMessage = clientConsumer.receive(500);
clientMessage.acknowledge();
Assert.assertNotNull(clientMessage);
Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
session.rollback();
}
Assert.assertNull(clientConsumer.receiveImmediate());
// Verify that original queue has a memory size of 0 and DLQ is greater than 0 after rollback
assertTrue(queueMemorySize1.get() == 0);
assertTrue(queueMemorySize2.get() > 0);
QueueControl dlqQueueControl = createManagementControl(dla, dlq);
assertMessageMetrics(dlqQueueControl, numMessagesToTest, durable);
// Retry all messages - i.e. they should go from DLQ to original Queue.
Assert.assertEquals(numMessagesToTest, dlqQueueControl.retryMessages());
// Assert DLQ is empty...
assertMessageMetrics(dlqQueueControl, 0, durable);
// Verify that original queue has a memory size of greater than 0 and DLQ is 0 after move
assertTrue(queueMemorySize1.get() > 0);
assertTrue(queueMemorySize2.get() == 0);
// .. and that the messages is now on the original queue once more.
for (int i = 0; i < numMessagesToTest; i++) {
ClientMessage clientMessage = clientConsumer.receive(500);
clientMessage.acknowledge();
Assert.assertNotNull(clientMessage);
Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
}
clientConsumer.close();
// Verify that original queue and DLQ have a memory size of 0
assertTrue(queueMemorySize1.get() == 0);
assertTrue(queueMemorySize2.get() == 0);
}
Aggregations