use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessagesToUnknownQueue.
@Test
public void testMoveMessagesToUnknownQueue() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString unknownQueue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send on queue
ClientMessage message = session.createMessage(durable);
SimpleString key = RandomUtil.randomSimpleString();
long value = RandomUtil.randomLong();
message.putLongProperty(key, value);
producer.send(message);
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 1, durable);
// moved all messages to unknown queue
try {
queueControl.moveMessages(null, unknownQueue.toString());
Assert.fail("operation must fail if the other queue does not exist");
} catch (Exception e) {
}
Assert.assertEquals(1, getMessageCount(queueControl));
assertMessageMetrics(queueControl, 1, durable);
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 testRetryMessage.
/**
* Test retry - get a message from DLQ and put on original queue.
*/
@Test
public void testRetryMessage() 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";
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);
producer.send(createTextMessage(session, sampleText));
session.start();
ClientConsumer clientConsumer = session.createConsumer(qName);
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);
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...
Assert.assertEquals(0, getMessageCount(queueControl));
assertMessageMetrics(queueControl, 0, durable);
// .. and that the message is now on the original queue once more.
clientMessage = clientConsumer.receive(500);
clientMessage.acknowledge();
Assert.assertNotNull(clientMessage);
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 testListDeliveringMessagesWithRASession.
// https://issues.jboss.org/browse/HORNETQ-1231
@Test
public void testListDeliveringMessagesWithRASession() throws Exception {
ServerLocator locator1 = createInVMNonHALocator().setBlockOnNonDurableSend(true).setConsumerWindowSize(10240).setAckBatchSize(0);
ClientSessionFactory sf = locator1.createSessionFactory();
final ClientSession transSession = sf.createSession(false, true, false);
ClientConsumer consumer = null;
SimpleString queue = null;
int numMsg = 10;
try {
// a session from RA does this
transSession.addMetaData("resource-adapter", "inbound");
transSession.addMetaData("jms-session", "");
SimpleString address = RandomUtil.randomSimpleString();
queue = RandomUtil.randomSimpleString();
transSession.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
final QueueControl queueControl = createManagementControl(address, queue);
ClientProducer producer = transSession.createProducer(address);
for (int i = 0; i < numMsg; i++) {
ClientMessage message = transSession.createMessage(durable);
message.putIntProperty(new SimpleString("seqno"), i);
producer.send(message);
}
consumer = transSession.createConsumer(queue);
transSession.start();
/**
* the following latches are used to make sure that
*
* 1. the first call on queueControl happens after the
* first message arrived at the message handler.
*
* 2. the message handler wait on the first message until
* the queueControl returns the right/wrong result.
*
* 3. the test exits after all messages are received.
*/
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(10);
consumer.setMessageHandler(new MessageHandler() {
@Override
public void onMessage(ClientMessage message) {
try {
message.acknowledge();
} catch (ActiveMQException e1) {
e1.printStackTrace();
}
latch1.countDown();
try {
latch2.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
latch3.countDown();
}
});
latch1.await(10, TimeUnit.SECONDS);
// now we know the ack of the message is sent but to make sure
// the server has received it, we try 5 times
int n = 0;
for (int i = 0; i < 5; i++) {
Thread.sleep(1000);
String jsonStr = queueControl.listDeliveringMessagesAsJSON();
n = countOccurrencesOf(jsonStr, "seqno");
if (n == numMsg) {
break;
}
}
assertEquals(numMsg, n);
latch2.countDown();
latch3.await(10, TimeUnit.SECONDS);
transSession.commit();
} finally {
consumer.close();
transSession.deleteQueue(queue);
transSession.close();
locator1.close();
}
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetConsumerJSON.
@Test
public void testGetConsumerJSON() throws Exception {
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.getConsumerCount());
ClientConsumer consumer = session.createConsumer(queue);
Assert.assertEquals(1, queueControl.getConsumerCount());
System.out.println("Consumers: " + queueControl.listConsumersAsJSON());
JsonArray obj = JsonUtil.readJsonArray(queueControl.listConsumersAsJSON());
assertEquals(1, obj.size());
consumer.close();
Assert.assertEquals(0, queueControl.getConsumerCount());
obj = JsonUtil.readJsonArray(queueControl.listConsumersAsJSON());
assertEquals(0, obj.size());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListMessageCounterHistory.
@Test
public void testListMessageCounterHistory() throws Exception {
long counterPeriod = 1000;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
QueueControl queueControl = createManagementControl(address, queue);
ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
serverControl.enableMessageCounters();
serverControl.setMessageCounterSamplePeriod(counterPeriod);
String jsonString = queueControl.listMessageCounterHistory();
DayCounterInfo[] infos = DayCounterInfo.fromJSON(jsonString);
Assert.assertEquals(1, infos.length);
session.deleteQueue(queue);
}
Aggregations