Search in sources :

Example 1 with QueueSession

use of javax.jms.QueueSession in project opennms by OpenNMS.

the class DaemonContextIT method canUseEmbeddedActiveMQBroker.

/**
	* Verifies that the embedded ActiveMQ broker bootstraps successfully
	* and is accessible using the provided connection factory.
	*/
@Test
public void canUseEmbeddedActiveMQBroker() throws Throwable {
    QueueConnection connection = activeMQConnectionFactory.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    TextMessage message = session.createTextMessage();
    message.setText("ping");
    QueueSender sender = session.createSender(session.createQueue("pong"));
    sender.send(message);
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 2 with QueueSession

use of javax.jms.QueueSession 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 3 with QueueSession

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

the class HelloMDB method sendReply.

private void sendReply(String msg, Queue destination, String messageID) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection("guest", "guest");
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        conn.start();
        QueueSender sender = session.createSender(destination);
        TextMessage message = session.createTextMessage(msg);
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 4 with QueueSession

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

the class QueueTestMDB method sendReply.

private void sendReply(Queue destination, String messageID, Exception e) throws JMSException {
    QueueConnection conn = qFactory.createQueueConnection();
    try {
        QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(destination);
        ObjectMessage message = session.createObjectMessage(e);
        message.setJMSCorrelationID(messageID);
        sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
    } finally {
        conn.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) ObjectMessage(javax.jms.ObjectMessage) QueueSession(javax.jms.QueueSession)

Example 5 with QueueSession

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

the class MessageDrivenTimeoutTestCase method sendMessage.

static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception {
    QueueConnection connection = getConnection(initCtx);
    connection.start();
    Queue replyDestination = null;
    try {
        final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        final Message message = session.createTextMessage(text);
        replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME);
        message.setJMSReplyTo(replyDestination);
        final Destination destination = (Destination) initCtx.lookup(queueJndi);
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
    } finally {
        connection.close();
    }
    return replyDestination;
}
Also used : Destination(javax.jms.Destination) QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Aggregations

QueueSession (javax.jms.QueueSession)17 QueueConnection (javax.jms.QueueConnection)14 TextMessage (javax.jms.TextMessage)14 Message (javax.jms.Message)10 Test (org.junit.Test)8 MessageProducer (javax.jms.MessageProducer)7 Queue (javax.jms.Queue)7 Destination (javax.jms.Destination)5 ObjectMessage (javax.jms.ObjectMessage)5 QueueConnectionFactory (javax.jms.QueueConnectionFactory)5 QueueReceiver (javax.jms.QueueReceiver)5 QueueSender (javax.jms.QueueSender)5 BytesMessage (javax.jms.BytesMessage)3 JMSException (javax.jms.JMSException)3 InitialContext (javax.naming.InitialContext)3 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Connection (javax.jms.Connection)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1