use of javax.jms.TemporaryQueue in project cxf by apache.
the class PooledConnectionTempQueueTest method sendWithReplyToTemp.
private static void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
Connection con = cf.createConnection();
con.start();
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Request");
msg.setJMSReplyTo(tempQueue);
MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
producer.send(msg);
// This sleep also seems to matter
Thread.sleep(500L);
MessageConsumer consumer = session.createConsumer(tempQueue);
Message replyMsg = consumer.receive();
assertNotNull(replyMsg);
// System.out.println(replyMsg.getJMSCorrelationID());
consumer.close();
producer.close();
session.close();
con.close();
}
use of javax.jms.TemporaryQueue in project iaf by ibissource.
the class MessagingSource method deleteDynamicQueue.
private void deleteDynamicQueue(Queue queue) throws IfsaException {
if (queue != null) {
try {
if (!(queue instanceof TemporaryQueue)) {
throw new IfsaException("Queue [" + queue.getQueueName() + "] is not a TemporaryQueue");
}
TemporaryQueue tqueue = (TemporaryQueue) queue;
tqueue.delete();
} catch (JMSException e) {
throw new IfsaException("cannot delete temporary queue", e);
}
}
}
use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.
the class AmqpManagementFacade method readEntityUsingAmqpManagement.
public Map<String, Object> readEntityUsingAmqpManagement(final Session session, final String type, final String name, final boolean actuals) throws JMSException {
Destination replyToDestination;
Destination replyConsumerDestination;
if (_protocol == Protocol.AMQP_1_0) {
replyToDestination = session.createTemporaryQueue();
replyConsumerDestination = replyToDestination;
} else {
replyToDestination = session.createQueue(AMQP_0_X_REPLY_TO_DESTINATION);
replyConsumerDestination = session.createQueue(AMQP_0_X_CONSUMER_REPLY_DESTINATION);
}
MessageConsumer consumer = session.createConsumer(replyConsumerDestination);
MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));
MapMessage request = session.createMapMessage();
request.setStringProperty("type", type);
request.setStringProperty("operation", "READ");
request.setString("name", name);
request.setString("object-path", name);
request.setStringProperty("index", "object-path");
request.setStringProperty("key", name);
request.setBooleanProperty("actuals", actuals);
request.setJMSReplyTo(replyToDestination);
producer.send(request);
if (session.getTransacted()) {
session.commit();
}
Message response = consumer.receive(5000);
if (session.getTransacted()) {
session.commit();
}
try {
if (response instanceof MapMessage) {
MapMessage bodyMap = (MapMessage) response;
Map<String, Object> data = new HashMap<>();
@SuppressWarnings("unchecked") Enumeration<String> keys = bodyMap.getMapNames();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
data.put(key, bodyMap.getObject(key));
}
return data;
} else if (response instanceof ObjectMessage) {
Object body = ((ObjectMessage) response).getObject();
if (body instanceof Map) {
@SuppressWarnings("unchecked") Map<String, ?> bodyMap = (Map<String, ?>) body;
return new HashMap<>(bodyMap);
}
}
throw new AmqpManagementFacade.OperationUnsuccessfulException("Management read failed : " + response.getStringProperty("statusCode") + " - " + response.getStringProperty("statusDescription"), response.getIntProperty("statusCode"));
} finally {
consumer.close();
if (_protocol == Protocol.AMQP_1_0) {
((TemporaryQueue) replyToDestination).delete();
}
}
}
use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.
the class AmqpManagementFacade method managementQueryObjects.
public List<Map<String, Object>> managementQueryObjects(final Session session, final String type) throws JMSException {
Destination replyToDestination;
Destination replyConsumerDestination;
if (_protocol == Protocol.AMQP_1_0) {
replyToDestination = session.createTemporaryQueue();
replyConsumerDestination = replyToDestination;
} else {
replyToDestination = session.createQueue(AMQP_0_X_REPLY_TO_DESTINATION);
replyConsumerDestination = session.createQueue(AMQP_0_X_CONSUMER_REPLY_DESTINATION);
}
MessageConsumer consumer = session.createConsumer(replyConsumerDestination);
MapMessage message = session.createMapMessage();
message.setStringProperty("identity", "self");
message.setStringProperty("type", "org.amqp.management");
message.setStringProperty("operation", "QUERY");
message.setStringProperty("entityType", type);
message.setString("attributeNames", "[]");
message.setJMSReplyTo(replyToDestination);
MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));
producer.send(message);
Message response = consumer.receive(5000);
try {
if (response instanceof MapMessage) {
MapMessage bodyMap = (MapMessage) response;
List<String> attributeNames = (List<String>) bodyMap.getObject("attributeNames");
List<List<Object>> attributeValues = (List<List<Object>>) bodyMap.getObject("results");
return getResultsAsMaps(attributeNames, attributeValues);
} else if (response instanceof ObjectMessage) {
Object body = ((ObjectMessage) response).getObject();
if (body instanceof Map) {
Map<String, ?> bodyMap = (Map<String, ?>) body;
List<String> attributeNames = (List<String>) bodyMap.get("attributeNames");
List<List<Object>> attributeValues = (List<List<Object>>) bodyMap.get("results");
return getResultsAsMaps(attributeNames, attributeValues);
}
}
throw new IllegalArgumentException("Cannot parse the results from a management query");
} finally {
consumer.close();
if (_protocol == Protocol.AMQP_1_0) {
((TemporaryQueue) replyToDestination).delete();
}
}
}
use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.
the class MessagingACLTest method testConsumeFromTempQueueFailure.
@Test
public void testConsumeFromTempQueueFailure() throws Exception {
configureACL(String.format("ACL ALLOW-LOG %s ACCESS VIRTUALHOST", USER1), String.format("ACL ALLOW-LOG %s CREATE QUEUE temporary=\"true\"", USER1), String.format("ACL DENY-LOG %s CONSUME QUEUE temporary=\"true\"", USER1), isLegacyClient() ? String.format("ACL ALLOW-LOG %s BIND EXCHANGE name=\"*\"", USER1) : "");
Connection connection = getConnectionBuilder().setUsername(USER1).setPassword(USER1_PASSWORD).build();
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
TemporaryQueue temporaryQueue = session.createTemporaryQueue();
try {
session.createConsumer(temporaryQueue);
fail("Exception is not thrown");
} catch (JMSException e) {
// pass
}
} finally {
try {
connection.close();
} catch (Exception e) {
LOGGER.error("Unexpected exception on connection close", e);
}
}
}
Aggregations