Search in sources :

Example 16 with QueueRequestor

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();
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) QueueConnection(javax.jms.QueueConnection) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 17 with QueueRequestor

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");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Example 18 with QueueRequestor

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));
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message)

Example 19 with QueueRequestor

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));
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message)

Aggregations

QueueRequestor (javax.jms.QueueRequestor)19 Message (javax.jms.Message)16 QueueSession (javax.jms.QueueSession)16 Queue (javax.jms.Queue)11 Connection (javax.jms.Connection)9 Session (javax.jms.Session)8 JMSException (javax.jms.JMSException)6 TextMessage (javax.jms.TextMessage)6 QueueConnection (javax.jms.QueueConnection)5 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)4 StringReader (java.io.StringReader)2 List (java.util.List)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 QueueConnectionFactory (javax.jms.QueueConnectionFactory)2 InitialContext (javax.naming.InitialContext)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 QueueBrowser (javax.jms.QueueBrowser)1