use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testPauseAndResume.
@Test
public void testPauseAndResume() {
long counterPeriod = 1000;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
try {
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
serverControl.enableMessageCounters();
serverControl.setMessageCounterSamplePeriod(counterPeriod);
Assert.assertFalse(queueControl.isPaused());
queueControl.pause();
Assert.assertTrue(queueControl.isPaused());
queueControl.resume();
Assert.assertFalse(queueControl.isPaused());
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRemoveMessagesWithLimit.
@Test
public void testRemoveMessagesWithLimit() 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);
assertMessageMetrics(queueControl, 2, durable);
// removed matching messages to otherQueue
int removedMatchedMessagesCount = queueControl.removeMessages(5, key + " =" + matchingValue);
Assert.assertEquals(1, removedMatchedMessagesCount);
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);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListMessagesWithFilter.
@Test
public void testListMessagesWithFilter() throws Exception {
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
String filter = key + " =" + matchingValue;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
ClientProducer producer = session.createProducer(address);
ClientMessage matchingMessage = session.createMessage(durable);
matchingMessage.putLongProperty(key, matchingValue);
producer.send(matchingMessage);
ClientMessage unmatchingMessage = session.createMessage(durable);
unmatchingMessage.putLongProperty(key, unmatchingValue);
producer.send(unmatchingMessage);
assertMessageMetrics(queueControl, 2, durable);
Map<String, Object>[] messages = queueControl.listMessages(filter);
Assert.assertEquals(1, messages.length);
Assert.assertEquals(matchingValue, Long.parseLong(messages[0].get("key").toString()));
consumeMessages(2, session, queue);
messages = queueControl.listMessages(filter);
Assert.assertEquals(0, messages.length);
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 testExpireMessage.
@Test
public void testExpireMessage() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString expiryAddress = RandomUtil.randomSimpleString();
SimpleString expiryQueue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
session.createQueue(expiryAddress, RoutingType.MULTICAST, expiryQueue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
QueueControl expiryQueueControl = createManagementControl(expiryAddress, expiryQueue);
assertMessageMetrics(queueControl, 1, durable);
assertMessageMetrics(expiryQueueControl, 0, durable);
// the message IDs are set on the server
Map<String, Object>[] messages = queueControl.listMessages(null);
Assert.assertEquals(1, messages.length);
long messageID = (Long) messages[0].get("messageID");
AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
boolean expired = queueControl.expireMessage(messageID);
Assert.assertTrue(expired);
Thread.sleep(200);
assertMessageMetrics(queueControl, 0, durable);
assertMessageMetrics(expiryQueueControl, 1, durable);
consumeMessages(0, session, queue);
consumeMessages(1, session, expiryQueue);
session.deleteQueue(queue);
session.deleteQueue(expiryQueue);
session.close();
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessagesWithFilter.
/**
* <ol>
* <li>send 2 message to queue</li>
* <li>move messages from queue to otherQueue using management method <em>with filter</em></li>
* <li>consume the message which <strong>did not</strong> matches the filter from queue</li>
* <li>consume the message which <strong>did</strong> matches the filter from otherQueue</li>
* </ol>
*/
@Test
public void testMoveMessagesWithFilter() throws Exception {
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString otherAddress = RandomUtil.randomSimpleString();
SimpleString otherQueue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
session.createQueue(otherAddress, RoutingType.MULTICAST, otherQueue, 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);
assertMessageMetrics(queueControl, 2, durable);
// moved matching messages to otherQueue
int movedMatchedMessagesCount = queueControl.moveMessages(key + " =" + matchingValue, otherQueue.toString());
Assert.assertEquals(1, movedMatchedMessagesCount);
Assert.assertEquals(1, getMessageCount(queueControl));
// 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));
// consume the matched message from otherQueue
ClientConsumer otherConsumer = session.createConsumer(otherQueue);
m = otherConsumer.receive(500);
Assert.assertNotNull(m);
Assert.assertEquals(matchingValue, m.getObjectProperty(key));
m.acknowledge();
consumer.close();
session.deleteQueue(queue);
otherConsumer.close();
session.deleteQueue(otherQueue);
}
Aggregations