Home > Uncategorized > Sending a message to JMS Queue

Sending a message to JMS Queue

Here is some code to send a message to a JMS queue using Spring:

ConnectionFactory connectionFactory = // Look up connectionfactory from JNDI
    Queue queue = // Look up distributed queue from JNDI
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.send(queue, new MessageCreator() {
        public Message createMessage(Session sessionthrows JMSException
        {
          ObjectMessage message = session.createObjectMessage();
          // Set the message content
          message.setObject(new Object());
          return message;
        } }
    );

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.