Search in sources :

Example 1 with QueueRequestor

use of javax.jms.QueueRequestor in project karaf by apache.

the class ArtemisDestinationSourceFactory method getNames.

private List<String> getNames(Connection connection, DestinationSource.DestinationType type) {
    try {
        QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue managementQueue = session.createQueue("activemq.management");
        QueueRequestor requestor = new QueueRequestor(session, managementQueue);
        connection.start();
        TextMessage m = session.createTextMessage();
        m.setStringProperty("_AMQ_ResourceName", "broker");
        m.setStringProperty("_AMQ_OperationName", "getQueueNames");
        String routing = type == DestinationSource.DestinationType.Queue ? "ANYCAST" : "MULTICAST";
        m.setText("[\"" + routing + "\"]");
        Message reply = requestor.request(m);
        String json = ((TextMessage) reply).getText();
        List<?> array = (List<?>) JsonReader.read(new StringReader(json));
        return (List<String>) array.get(0);
    } catch (Exception e) {
        return Collections.emptyList();
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) QueueConnection(javax.jms.QueueConnection) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) StringReader(java.io.StringReader) List(java.util.List) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException)

Example 2 with QueueRequestor

use of javax.jms.QueueRequestor in project activemq-artemis by apache.

the class QueueRequestorExample method main.

public static void main(final String[] args) throws Exception {
    QueueConnection connection = null;
    InitialContext initialContext = null;
    try {
        // Step 1. Create an initial context to perform the JNDI lookup.
        initialContext = new InitialContext();
        // Step 2. Perfom a lookup on the queue
        Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
        // Step 3. Look-up the JMS queue connection factory
        QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("ConnectionFactory");
        // Step 4. Create a TextReverserService which consumes messages from the queue and sends message with reversed
        // text
        TextReverserService reverserService = new TextReverserService(cf, queue);
        // Step 5. Create a JMS QueueConnection
        connection = cf.createQueueConnection();
        // Step 6. Start the connection
        connection.start();
        // Step 7. Create a JMS queue session with AUTO_ACKNOWLEDGE mode
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        // Step 8. Create a JMS queue requestor to send requests to the queue
        QueueRequestor queueRequestor = new QueueRequestor(session, queue);
        // Step 9. Create a JMS message to send as a request
        TextMessage request = session.createTextMessage("Hello, World!");
        // Step 10. Use the requestor to send the request and wait to receive a reply
        TextMessage reply = (TextMessage) queueRequestor.request(request);
        // Step 11. The reply's text contains the reversed request's text
        System.out.println("Send request: " + request.getText());
        System.out.println("Received reply:" + reply.getText());
        // Step.12 close the queue requestor
        queueRequestor.close();
        // Step 13. close the text reverser service
        reverserService.close();
    } finally {
        if (connection != null) {
            try {
                // Step 14. Be sure to close the JMS resources!
                connection.close();
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
        if (initialContext != null) {
            // Also the InitialContext
            initialContext.close();
        }
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 3 with QueueRequestor

use of javax.jms.QueueRequestor in project activemq-artemis by apache.

the class QueueBridgeTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    context = createApplicationContext();
    createConnections();
    requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue theQueue = requestServerSession.createQueue(getClass().getName());
    requestServerConsumer = requestServerSession.createConsumer(theQueue);
    requestServerConsumer.setMessageListener(this);
    requestServerProducer = requestServerSession.createProducer(null);
    QueueSession session = remoteConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    requestor = new QueueRequestor(session, theQueue);
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Example 4 with QueueRequestor

use of javax.jms.QueueRequestor in project activemq-artemis by apache.

the class PurgeCommandTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    context = createApplicationContext();
    createConnections();
    requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    theQueue = requestServerSession.createQueue(QUEUE_NAME);
    requestServerConsumer = requestServerSession.createConsumer(theQueue);
    requestServerProducer = requestServerSession.createProducer(null);
    QueueSession session = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    requestor = new QueueRequestor(session, theQueue);
}
Also used : QueueRequestor(javax.jms.QueueRequestor) QueueSession(javax.jms.QueueSession)

Example 5 with QueueRequestor

use of javax.jms.QueueRequestor in project wildfly by wildfly.

the class DestinationConfiguration method destroyQueue.

public void destroyQueue(ConnectionFactory cf, Queue managementQueue, String queueName) throws JMSException {
    try (Connection connection = createQueueConnection(cf);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
        connection.start();
        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);
        ROOT_LOGGER.debugf("Deleting queue %s returned %s", queueName, reply);
        requestor.close();
        if (!reply.getBooleanProperty("_AMQ_OperationSucceeded")) {
            throw ROOT_LOGGER.remoteDestinationDeletionFailed(queueName, reply.getBody(String.class));
        }
        ROOT_LOGGER.debugf("Queue %s has been deleted", queueName);
    }
}
Also used : QueueRequestor(javax.jms.QueueRequestor) Message(javax.jms.Message) Connection(javax.jms.Connection) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session)

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