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();
}
}
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();
}
}
}
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);
}
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);
}
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);
}
}
Aggregations