use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRetryDivertedMessage.
/**
* Test retry - get a diverted message from DLQ and put on original queue.
*/
@Test
public void testRetryDivertedMessage() throws Exception {
final SimpleString dla = new SimpleString("DLA");
final SimpleString dlq = new SimpleString("DLQ");
final SimpleString forwardingQueue = new SimpleString("forwardingQueue");
final SimpleString forwardingAddress = new SimpleString("forwardingAddress");
final SimpleString myTopic = new SimpleString("myTopic");
final String sampleText = "Put me on DLQ";
AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
server.getAddressSettingsRepository().addMatch(forwardingAddress.toString(), addressSettings);
// create target queue, DLQ and source topic
session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
session.createQueue(forwardingAddress, RoutingType.MULTICAST, forwardingQueue, null, durable);
session.createAddress(myTopic, RoutingType.MULTICAST, false);
DivertConfiguration divert = new DivertConfiguration().setName("local-divert").setRoutingName("some-name").setAddress(myTopic.toString()).setForwardingAddress(forwardingAddress.toString()).setExclusive(false);
server.deployDivert(divert);
// Send message to topic.
ClientProducer producer = session.createProducer(myTopic);
producer.send(createTextMessage(session, sampleText));
session.start();
ClientConsumer clientConsumer = session.createConsumer(forwardingQueue);
ClientMessage clientMessage = clientConsumer.receive(500);
clientMessage.acknowledge();
Assert.assertNotNull(clientMessage);
Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
// force a rollback to DLQ
session.rollback();
clientMessage = clientConsumer.receiveImmediate();
Assert.assertNull(clientMessage);
QueueControl queueControl = createManagementControl(dla, dlq, RoutingType.MULTICAST);
assertMessageMetrics(queueControl, 1, durable);
final long messageID = getFirstMessageId(queueControl);
// Retry the message - i.e. it should go from DLQ to original Queue.
Assert.assertTrue(queueControl.retryMessage(messageID));
// Assert DLQ is empty...
assertMessageMetrics(queueControl, 0, durable);
// .. and that the message is now on the original queue once more.
clientMessage = clientConsumer.receive(500);
// fails because of AMQ222196 !!!
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
Assert.assertEquals(sampleText, clientMessage.getBodyBuffer().readString());
clientConsumer.close();
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testExpireMessagesWithFilter.
@Test
public void testExpireMessagesWithFilter() throws Exception {
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
ClientMessage matchingMessage = session.createMessage(durable);
matchingMessage.putLongProperty(key, matchingValue);
producer.send(matchingMessage);
ClientMessage unmatchingMessage = session.createMessage(durable);
unmatchingMessage.putLongProperty(key, unmatchingValue);
producer.send(unmatchingMessage);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(2, getMessageCount(queueControl));
int expiredMessagesCount = queueControl.expireMessages(key + " =" + matchingValue);
Assert.assertEquals(1, expiredMessagesCount);
assertMessageMetrics(queueControl, 1, durable);
// consume the unmatched message from queue
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage m = consumer.receive(500);
Assert.assertNotNull(m);
Assert.assertEquals(unmatchingValue, m.getObjectProperty(key));
m.acknowledge();
// check there is no other message to consume:
m = consumer.receiveImmediate();
Assert.assertNull(m);
consumer.close();
session.deleteQueue(queue);
session.close();
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRemoveMessagesWithNullFilter.
@Test
public void testRemoveMessagesWithNullFilter() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
producer.send(session.createMessage(durable));
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 2, durable);
// removed matching messages to otherQueue
int removedMatchedMessagesCount = queueControl.removeMessages(null);
Assert.assertEquals(2, removedMatchedMessagesCount);
assertMessageMetrics(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 testRemoveScheduledMessage.
@Test
public void testRemoveScheduledMessage() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send 2 messages on queue, both scheduled
long timeout = System.currentTimeMillis() + 5000;
ClientMessage m1 = session.createMessage(durable);
m1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, timeout);
producer.send(m1);
ClientMessage m2 = session.createMessage(durable);
m2.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, timeout);
producer.send(m2);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(2, queueControl.getScheduledCount());
// the message IDs are set on the server
Map<String, Object>[] messages = queueControl.listScheduledMessages();
Assert.assertEquals(2, messages.length);
long messageID = (Long) messages[0].get("messageID");
// delete 1st message
boolean deleted = queueControl.removeMessage(messageID);
Assert.assertTrue(deleted);
assertScheduledMetrics(queueControl, 1, durable);
// check there is a single message to consume from queue
while (timeout > System.currentTimeMillis() && queueControl.getScheduledCount() == 1) {
Thread.sleep(100);
}
consumeMessages(1, 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 testRemoveAllMessages.
@Test
public void testRemoveAllMessages() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
producer.send(session.createMessage(durable));
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 2, durable);
// removed matching messages to otherQueue
int removedMatchedMessagesCount = queueControl.removeAllMessages();
Assert.assertEquals(2, removedMatchedMessagesCount);
assertMessageMetrics(queueControl, 0, durable);
session.deleteQueue(queue);
}
Aggregations