Search in sources :

Example 21 with Destination

use of javax.jms.Destination 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)

Example 22 with Destination

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

the class SimpleTimerMDBTestCase method sendMessage.

//the timer is created when the
public void sendMessage() throws Exception {
    final InitialContext ctx = new InitialContext();
    final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
    final TopicConnection connection = factory.createTopicConnection();
    connection.start();
    try {
        final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        final Message message = session.createTextMessage("Test");
        final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
    } finally {
        connection.close();
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) Destination(javax.jms.Destination) TopicSession(javax.jms.TopicSession) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) TopicConnection(javax.jms.TopicConnection) InitialContext(javax.naming.InitialContext)

Example 23 with Destination

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

the class ReplyUtil method reply.

public static void reply(ConnectionFactory factory, Message message) {
    Connection connection = null;
    try {
        connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Destination destination = message.getJMSReplyTo();
        // ignore messages that need no reply
        if (destination == null)
            return;
        final MessageProducer replyProducer = session.createProducer(destination);
        final Message replyMsg = session.createMessage();
        replyMsg.setJMSCorrelationID(message.getJMSMessageID());
        replyProducer.send(replyMsg);
        replyProducer.close();
    } catch (JMSException e) {
        throw new RuntimeException(e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
            }
        }
    }
}
Also used : Destination(javax.jms.Destination) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 24 with Destination

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

the class MessagingEjb method reply.

public void reply(final Message message) throws JMSException {
    final Destination destination = message.getJMSReplyTo();
    // ignore messages that need no reply
    if (destination == null) {
        return;
    }
    final Message replyMsg = session.createTextMessage("replying to message: " + message.toString());
    replyMsg.setJMSCorrelationID(message.getJMSMessageID());
    this.sendMessage(replyMsg, destination, null);
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message)

Example 25 with Destination

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

the class SimpleMDB method onMessage.

@Override
public void onMessage(Message message) {
    logger.trace("Received message: " + message);
    try {
        final Destination replyTo = message.getJMSReplyTo();
        if (replyTo != null) {
            logger.trace("Replying to " + replyTo);
            try (JMSContext context = factory.createContext()) {
                String reply = (messageDrivenContext != null) ? SUCCESS_REPLY : FAILURE_REPLY;
                context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
            }
        }
    } catch (JMSException jmse) {
        throw new RuntimeException(jmse);
    }
}
Also used : Destination(javax.jms.Destination) JMSException(javax.jms.JMSException) JMSContext(javax.jms.JMSContext)

Aggregations

Destination (javax.jms.Destination)178 Test (org.junit.Test)51 TextMessage (javax.jms.TextMessage)47 Session (javax.jms.Session)46 JMSException (javax.jms.JMSException)45 Connection (javax.jms.Connection)32 MessageProducer (javax.jms.MessageProducer)31 Message (javax.jms.Message)30 ConnectionFactory (javax.jms.ConnectionFactory)24 MessageConsumer (javax.jms.MessageConsumer)24 JMSContext (javax.jms.JMSContext)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ObjectMessage (javax.jms.ObjectMessage)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 InitialContext (javax.naming.InitialContext)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 Queue (javax.jms.Queue)8 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 MapMessage (javax.jms.MapMessage)7 HashMap (java.util.HashMap)6