activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avin98 <avi...@yahoo.com>
Subject Urgent: Message Delivery
Date Wed, 12 Jul 2006 00:51:05 GMT

Hi

This is a basic question on the Message Delivery: Does a notification that a
message has been successfully get sent to the JMS server only after the
onMessage completes ? 

Can someone please help me out ....

I have the following piece of code

servlet Code
----------------

doPost() {

            // Post message on QUEUE 1
            sendMessage(request.getParameter("message"));
                                   
            //Receive message from QUEUE 2
            receiveMessage();

}

EJB Code
------------

// OnMessage of QUEUE 1
public void onMessage(Message msg) {

       // POST message on QUEUE 2
       sendMessage(msg.getText());

   
       // Receive message on QUEUE3
      receiveMessage();

}


My servlet posts a message onto QUEUE1 (which inturn invokes the MDB) and
listens on QUEUE2.

So, my OnMessage actually POSTS message onto Queue 2 and listens on Queue 3.

But my servlet whichs listens on QUEUE2, never gets a notification that a
message has been delivered into QUEUE2 .....Why is this ???




Here is my code for sending message:

=======================

public void sendMessage(String query){

InitialContext naming = new InitialContext();

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


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

            // lookup jms queue
            Queue queue = (Queue) naming.lookup(queueName);
            
            System.out.println("The Queue is:"+queue);
            
            // create jms session
            boolean transacted = false;
            publishSession = connection.createQueueSession(transacted,
Session.CLIENT_ACKNOWLEDGE);
            
            
            sender = publishSession.createSender(queue);
           
            sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            
            

            TextMessage message = publishSession.createTextMessage();           
            // Get new user information from request and populate the
message with that info.
            System.out.println("StreamService: Setting the
message===>"+query);
            message.setText(query);
           
            
            sender.send(message);
}
=========================

public String receiveMessage() {

// lookup queue connection factory
        QueueConnectionFactory connectionFactory = (QueueConnectionFactory)
naming
            .lookup(connectionFactoryName);
      
        // create jms connection
        QueueConnection connection = connectionFactory
            .createQueueConnection();
        
        // System.out.println("Connection is:"+ connection);

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

        // create a session.
        QueueSession session = connection.createQueueSession(false,
            Session.CLIENT_ACKNOWLEDGE);
        
        
        // create a QueueReceiver
        QueueReceiver receiver = session.createReceiver(queue);
                
        
        //Start the connection
        connection.start();        
        
        
        // receive a message from the queue, wait 10 seconds
        try {
         
            message = (TextMessage) receiver.receive();
         
            if(message !=null) {
                msg = ((TextMessage) message).getText();
                message.acknowledge();
            }

            return msg;

}

Here is the code for receive message
-- 
View this message in context: http://www.nabble.com/Urgent%3A-Message-Delivery-tf1928223.html#a5280907
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message