use of javax.jms.QueueRequestor in project activemq-artemis by apache.
the class NewQueueRequestorTest method testQueueRequestor.
@Test
public void testQueueRequestor() throws Exception {
QueueConnection conn1 = null, conn2 = null;
try {
Queue queue1 = createQueue(true, "myQueue");
conn1 = (QueueConnection) cf.createConnection();
QueueSession sess1 = conn1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueRequestor requestor = new QueueRequestor(sess1, queue1);
conn1.start();
// And the responder
conn2 = (QueueConnection) cf.createConnection();
QueueSession sess2 = conn2.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TestMessageListener listener = new TestMessageListener(sess2);
QueueReceiver receiver = sess2.createReceiver(queue1);
receiver.setMessageListener(listener);
conn2.start();
Message m1 = sess1.createMessage();
log.trace("Sending request message");
TextMessage m2 = (TextMessage) requestor.request(m1);
assertNotNull(m2);
assertEquals("This is the response", m2.getText());
requestor.close();
} finally {
conn1.close();
conn2.close();
}
}
use of javax.jms.QueueRequestor in project wildfly by wildfly.
the class RemoteActiveMQProviderJMSOperations method deleteRemoteQueue.
private void deleteRemoteQueue(String queueName) {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616", "guest", "guest");
try (Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
connection.start();
Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor((QueueSession) session, managementQueue);
Message m = session.createMessage();
org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER, "destroyQueue", queueName, true, true);
Message reply = requestor.request(m);
System.out.println("Deleting queue " + queueName + " returned " + reply);
if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
String body = reply.getBody(String.class);
System.out.println("Deleting of queue " + queueName + " has failed because of " + body);
}
} catch (JMSException ex) {
ex.printStackTrace();
throw new JMSOperationsException(ex);
}
System.out.println("Queue " + queueName + " has been deleted");
}
use of javax.jms.QueueRequestor in project wildfly by wildfly.
the class MDB20MessageSelectorTestCase method purgeQueue.
/**
* Removes all message son a queue
*
* @param queueName name of the queue
* @throws Exception
*/
private void purgeQueue(String queueName) throws Exception {
QueueRequestor requestor = new QueueRequestor((QueueSession) session, ActiveMQJMSClient.createQueue("activemq.management"));
Message m = session.createMessage();
org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.QUEUE + "jms.queue." + queueName, "removeAllMessages");
Message reply = requestor.request(m);
if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
logger.warn(reply.getBody(String.class));
}
}
use of javax.jms.QueueRequestor in project wildfly by wildfly.
the class MDB20QueueTestCase method purgeQueue.
/**
* Removes all message son a queue
*
* @param queueName name of the queue
* @throws Exception
*/
private void purgeQueue(String queueName) throws Exception {
QueueRequestor requestor = new QueueRequestor((QueueSession) session, ActiveMQJMSClient.createQueue("activemq.management"));
Message m = session.createMessage();
org.apache.activemq.artemis.api.jms.management.JMSManagementHelper.putOperationInvocation(m, ResourceNames.QUEUE + "jms.queue." + queueName, "removeAllMessages");
Message reply = requestor.request(m);
if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
logger.warn(reply.getBody(String.class));
}
}
Aggregations