Search in sources :

Example 76 with TemporaryQueue

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();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 77 with TemporaryQueue

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);
        }
    }
}
Also used : IfsaException(nl.nn.adapterframework.extensions.ifsa.IfsaException) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException)

Example 78 with TemporaryQueue

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();
        }
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) StreamMessage(javax.jms.StreamMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) HashMap(java.util.HashMap) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 79 with TemporaryQueue

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();
        }
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) StreamMessage(javax.jms.StreamMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) ArrayList(java.util.ArrayList) List(java.util.List) MessageProducer(javax.jms.MessageProducer) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 80 with TemporaryQueue

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);
        }
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5