activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avin98 <avi...@yahoo.com>
Subject Active MQ 3.2.1 QueueSender
Date Mon, 10 Jul 2006 20:56:20 GMT

When you try to send a message to a queue in ActiveMQ 3.2.2 (bundled along
with geronimo), it doesn't work the first time.

Why is this ??? I faced the same problem with the samples as well, when I
try to send message from a servlet.

Here is the code snippet that does that:

        QueueSession session = null;
        QueueSender sender = null;
        TextMessage message = null;
        String correlationId = null;
        QueueConnection connection = null;
        String connectionFactoryName = "java:comp/env/jms/broker";
        String queueName = "java:comp/env/jms/queue/OutboundQueue";
        try {

            InitialContext naming = new InitialContext();

            // lookup queue connection factory
            QueueConnectionFactory connectionFactory =
(QueueConnectionFactory) naming
                .lookup(connectionFactoryName);

            // create jms connection
            connection = connectionFactory
                .createQueueConnection();

            // System.out.println("Connection is:"+ connection);

            // lookup jms queue
            Queue queue = (Queue) naming.lookup(queueName);

            // create a session.
            session = connection.createQueueSession(false,
                Session.AUTO_ACKNOWLEDGE);

            // create a QueueSender
            sender = session.createSender(queue);
            sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            
            // create a message to send to the queue...
            message = session.createTextMessage();
            
            message.setText(dataStream);
 

            // send
            sender.send(message);
            
            // store the messageID as correlationID
            correlationId = message.getJMSMessageID();
            
            

        } catch (Exception je) {
            je.printStackTrace();

        } finally {
            try {
                if (sender != null)
                    sender.close();
                if (session != null)
                    session.close();
                if(connection !=null)
                    connection.close();
             } catch (JMSException je) {
                je.printStackTrace();

            }
        }
 
-- 
View this message in context: http://www.nabble.com/Active-MQ-3.2.1-QueueSender-tf1920777.html#a5259006
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message