You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Pico Florin <pi...@yahoo.co.uk> on 2006/10/03 10:17:08 UTC

Need simple example for receiving a JMS message

Hi, all!
    I'm newbie in using the activemq API and I have some problems in receiving a JMS message from a web server. Here is the scenario:
    I have a reach client who sends JMS messages to a web server (Tomcat) and it (the client) expects a reply from the server. I have read the documentation related to this subject from here:
    http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
   
  but I'm a litlle bit confused because of this lines of code (bolded):
   
  //server side

public void onMessage(Message request) {      Message response = session.createMessage();    response.setJMSCorrelationID(request.getJMSCorrelationID())      producer.send(request.getJMSReplyTo(), response)  }
  1. In this case who is the session and how can I obtain it?  
  2. Who is the producer and how can I obtain it?
   
  On the client should I use the code:
   

// client side  Destination tempDest = session.createTemporaryQueue();  MessageConsumer responseConsumer = session.createConsumer(tempDest);  ...    // send a request..  message.setJMSReplyTo(tempDest)  message.setJMSCorrelationID(myCorrelationID);    producer.send(message);
  responseConsumer.receive(1000); 
   
  in order to receive the message?
   
  Thank you,
     Florin
   
   
    
   
   
   
   
   
   
   
    
    

 		
---------------------------------
Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail 

Re: Need simple example for receiving a JMS message

Posted by Pico Florin <pi...@yahoo.co.uk>.
Hi!
    Thank you for your responses. I found this link that I hope that it covers what I want:
  
   http://www.enterpriseintegrationpatterns.com/RequestReplyJmsExample.html
  
  Regards,
    Florin

James Strachan <ja...@gmail.com> wrote:  On 10/3/06, Pico Florin 
 wrote:
> Hi!
>     The provided examples don't covered what I want.

Why not?

>  I have just a reach client (made swing) who sends an object an expects  a response from the web server(tomcat). I want to know if it  functionality is doable without any configuration file but  programatically.

It can but its much easier to use Spring to do the wiring.


> Also in the:
>
>    http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
>
>  is written that you can use the MultiplexingRequestor but I didn't see  any example that use this class neither in server side nor in the  client side.

There's no examples I don't think; just javadoc :)


> The bigest problem for me is how should I write the server  side in order to send a message to the reach client.

try getting used to the JMS API by the aforementioned Sun tutorial,
then just follow the pseudo code on this page.


http://activemq.org/site/how-should-i-implement-request-response-with-jms.html

-- 

James
-------
http://radio.weblogs.com/0112098/



 		
---------------------------------
 All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine

Re: Need simple example for receiving a JMS message

Posted by James Strachan <ja...@gmail.com>.
On 10/3/06, Pico Florin <pi...@yahoo.co.uk> wrote:
> Hi!
>     The provided examples don't covered what I want.

Why not?

> I have just a  reach client (made swing) who sends an object an expects a response  from the web server(tomcat). I want to know if it functionality is  doable without any configuration file but programatically.

It can but its much easier to use Spring to do the wiring.


> Also in the:
>
>    http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
>
>   is written that you can use the MultiplexingRequestor but I didn't see  any example that use this class neither in server side nor in the  client side.

There's no examples I don't think; just javadoc :)


> The bigest problem for me is how should I write the server  side in order to send a message to the reach client.

try getting used to the JMS API by the aforementioned Sun tutorial,
then just follow the pseudo code on this page.


http://activemq.org/site/how-should-i-implement-request-response-with-jms.html

-- 

James
-------
http://radio.weblogs.com/0112098/

Re: Need simple example for receiving a JMS message

Posted by Pico Florin <pi...@yahoo.co.uk>.
Hi!
    The provided examples don't covered what I want. I have just a  reach client (made swing) who sends an object an expects a response  from the web server(tomcat). I want to know if it functionality is  doable without any configuration file but programatically. Also in the:
  
   http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
  
  is written that you can use the MultiplexingRequestor but I didn't see  any example that use this class neither in server side nor in the  client side. The bigest problem for me is how should I write the server  side in order to send a message to the reach client.
   Regards,
    Florin
  

James Strachan <ja...@gmail.com> wrote:  I'd recommend you follow the Lingo examples and use it on both the
client and server (at least until you get used to JMS). Failing that
use the JMS API on both ends.

this example has the client and server side...

http://lingo.codehaus.org/Example

(just separate them into 2 different spring.xml if you want)

On 10/3/06, Pico Florin 
 wrote:
> Hello!
>  Thank you for your respose. I've used lingo just for the client side. I  still have problems in setting the server side response. How can I set  up the server side in order to send a response to the client's message?  More clear, I have to know how to set up the client in order to be a  sender not just a consumer. I have made the following:
>   //on the servert side
>   public class SynchronizeListener implements MessageListener {
>   Session session;
>   public SynchronizeListener(Session session ){
>    this.session = session;
>   }
>
>   public void onMessage(Message msg) {
>
>                   Message response = session
>                             .createTextMessage("Replying from server for "
>                                     + m.getObject());
>                     response.setJMSCorrelationID(msg.getJMSCorrelationID());
>
>                   producer = session.createProducer(msg.getJMSReplyTo());
>
>
>                   producer.send(response);
>
>               }
>
>       }
>   }
>
>  This listener is added to the server side consumer. The JMS server is  starded from a servlet, and here is the code where I use the above  class:
>
>   public class ApplicationInit implements ServletContextListener {
>
>   public void contextInitialized(ServletContextEvent e) {
>     BrokerService jmsServer = new BrokerService();
>
>
>                         jmsServer.addConnector("tcp://localhost:61615");
>                         jmsServer.addConnector("tcp://localhost:61616");
>                       jmsServer.start();
>                        ActiveMQConnectionFactory factory  = new ActiveMQConnectionFactory(
>                                 "tcp://localhost:61615");
>                        Connection conn =  factory.createConnection();
>                       conn.start();
>                        Session session =  conn.createSession(true,
>                                 Session.AUTO_ACKNOWLEDGE);
>
>                       Queue queue = session.createQueue("SYNCHRONIZE");
>                         MessageConsumer listener = session.createConsumer(queue);
>
>                         listener.setMessageListener(new AuditorSynchronizeListener(
>                                 session));
>   }
>
> }
>   But when I start the client the following exception is thrown:
>
>   javax.jms.JMSException: edu.emory.mathcs.backport.java.util.concurrent.TimeoutException
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.createJMSException(MultiplexingRequestor.java:205)
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:133)
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:95)
>       at
>   Evicting inactive request for correlationID: Entry for key: 1
>
>   in the client code:
>
>   Queue messageQueue = session.createQueue("SYNCHRONIZE");
>               MessageProducer producer = session.createProducer(messageQueue);
>               producer.setTimeToLive(5000);
>
>               Destination tempDest = session
>               .createTemporaryQueue();
>               MultiplexingRequestor multp = new MultiplexingRequestor(conn,
>                        session, producer, messageQueue,  tempDest, true);
>
>               Message msg = null;
>
>               msg = session.createObjectMessage("Testing the client ");
>               System.out.println("received =" +multp.request(messageQueue, msg));
>
> James Strachan  wrote:  If you want to learn how to use the JMS API then Sun's JMS tutorial is
> a pretty good start...
>
> http://incubator.apache.org/activemq/how-do-i-get-started-with-jms.html
>
> Alternatively you could stick to writing business level POJOs and hide
> the middleware via Lingo which hides the JMS API from you letting you
> focus on your business logic
>
> http://lingo.codehaus.org/
>
>
> On 10/3/06, Pico Florin
>  wrote:
> > Hi, all!
>  > I'm newbie in using the activemq API and I have some problems in  receiving a JMS message from a web server. Here is the scenario:
>  > I have a reach client who sends JMS messages to a web server  (Tomcat) and it (the client) expects a reply from the server. I have  read the documentation related to this subject from here:
> >     http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
> >
> >   but I'm a litlle bit confused because of this lines of code (bolded):
> >
> >   //server side
> >
>  > public void onMessage(Message request) { Message response =  session.createMessage();  response.setJMSCorrelationID(request.getJMSCorrelationID())  producer.send(request.getJMSReplyTo(), response) }
> >   1. In this case who is the session and how can I obtain it?
> >   2. Who is the producer and how can I obtain it?
> >
> >   On the client should I use the code:
> >
> >
>  > // client side Destination tempDest =  session.createTemporaryQueue(); MessageConsumer responseConsumer =  session.createConsumer(tempDest); ... // send a request..  message.setJMSReplyTo(tempDest)  message.setJMSCorrelationID(myCorrelationID); producer.send(message);
> >   responseConsumer.receive(1000);
> >
> >   in order to receive the message?
> >
> >   Thank you,
> >      Florin
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail
> >
>
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
>
>
> ---------------------------------
>  Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail.
>


-- 

James
-------
http://radio.weblogs.com/0112098/



 		
---------------------------------
 To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.

Re: Need simple example for receiving a JMS message

Posted by James Strachan <ja...@gmail.com>.
I'd recommend you follow the Lingo examples and use it on both the
client and server (at least until you get used to JMS). Failing that
use the JMS API on both ends.

this example has the client and server side...

http://lingo.codehaus.org/Example

(just separate them into 2 different spring.xml if you want)

On 10/3/06, Pico Florin <pi...@yahoo.co.uk> wrote:
> Hello!
>    Thank you for your respose. I've used lingo just for the client  side. I still have problems in setting the server side response. How  can I set up the server side in order to send a response to the  client's message? More clear, I have to know how to set up the client  in order to be a sender not just a consumer. I have made the following:
>   //on the servert side
>   public class SynchronizeListener implements MessageListener {
>   Session session;
>   public SynchronizeListener(Session session ){
>    this.session = session;
>   }
>
>   public void onMessage(Message msg) {
>
>                   Message response = session
>                             .createTextMessage("Replying from server for "
>                                     + m.getObject());
>                     response.setJMSCorrelationID(msg.getJMSCorrelationID());
>
>                   producer = session.createProducer(msg.getJMSReplyTo());
>
>
>                   producer.send(response);
>
>               }
>
>       }
>   }
>
>   This listener is added to the server side consumer. The JMS server is  starded from a servlet, and here is the code where I use the above  class:
>
>   public class ApplicationInit implements ServletContextListener {
>
>   public void contextInitialized(ServletContextEvent e) {
>     BrokerService jmsServer = new BrokerService();
>
>
>                         jmsServer.addConnector("tcp://localhost:61615");
>                         jmsServer.addConnector("tcp://localhost:61616");
>                       jmsServer.start();
>                        ActiveMQConnectionFactory factory  = new ActiveMQConnectionFactory(
>                                 "tcp://localhost:61615");
>                        Connection conn =  factory.createConnection();
>                       conn.start();
>                        Session session =  conn.createSession(true,
>                                 Session.AUTO_ACKNOWLEDGE);
>
>                       Queue queue = session.createQueue("SYNCHRONIZE");
>                         MessageConsumer listener = session.createConsumer(queue);
>
>                         listener.setMessageListener(new AuditorSynchronizeListener(
>                                 session));
>   }
>
> }
>   But when I start the client the following exception is thrown:
>
>   javax.jms.JMSException: edu.emory.mathcs.backport.java.util.concurrent.TimeoutException
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.createJMSException(MultiplexingRequestor.java:205)
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:133)
>       at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:95)
>       at
>   Evicting inactive request for correlationID: Entry for key: 1
>
>   in the client code:
>
>   Queue messageQueue = session.createQueue("SYNCHRONIZE");
>               MessageProducer producer = session.createProducer(messageQueue);
>               producer.setTimeToLive(5000);
>
>               Destination tempDest = session
>               .createTemporaryQueue();
>               MultiplexingRequestor multp = new MultiplexingRequestor(conn,
>                        session, producer, messageQueue,  tempDest, true);
>
>               Message msg = null;
>
>               msg = session.createObjectMessage("Testing the client ");
>               System.out.println("received =" +multp.request(messageQueue, msg));
>
> James Strachan <ja...@gmail.com> wrote:  If you want to learn how to use the JMS API then Sun's JMS tutorial is
> a pretty good start...
>
> http://incubator.apache.org/activemq/how-do-i-get-started-with-jms.html
>
> Alternatively you could stick to writing business level POJOs and hide
> the middleware via Lingo which hides the JMS API from you letting you
> focus on your business logic
>
> http://lingo.codehaus.org/
>
>
> On 10/3/06, Pico Florin
>  wrote:
> > Hi, all!
> >  I'm newbie in using the activemq API and I have some problems in  receiving a JMS message from a web server. Here is the scenario:
> >  I have a reach client who sends JMS messages to a web server (Tomcat)  and it (the client) expects a reply from the server. I have read the  documentation related to this subject from here:
> >     http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
> >
> >   but I'm a litlle bit confused because of this lines of code (bolded):
> >
> >   //server side
> >
> >  public void onMessage(Message request) { Message response =  session.createMessage();  response.setJMSCorrelationID(request.getJMSCorrelationID())  producer.send(request.getJMSReplyTo(), response) }
> >   1. In this case who is the session and how can I obtain it?
> >   2. Who is the producer and how can I obtain it?
> >
> >   On the client should I use the code:
> >
> >
> >  // client side Destination tempDest = session.createTemporaryQueue();  MessageConsumer responseConsumer = session.createConsumer(tempDest);  ... // send a request.. message.setJMSReplyTo(tempDest)  message.setJMSCorrelationID(myCorrelationID); producer.send(message);
> >   responseConsumer.receive(1000);
> >
> >   in order to receive the message?
> >
> >   Thank you,
> >      Florin
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail
> >
>
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
>
>
> ---------------------------------
>  Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail.
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Re: Need simple example for receiving a JMS message

Posted by Pico Florin <pi...@yahoo.co.uk>.
Hello!
   Thank you for your respose. I've used lingo just for the client  side. I still have problems in setting the server side response. How  can I set up the server side in order to send a response to the  client's message? More clear, I have to know how to set up the client  in order to be a sender not just a consumer. I have made the following:
  //on the servert side
  public class SynchronizeListener implements MessageListener {
  Session session;
  public SynchronizeListener(Session session ){
   this.session = session;
  }
   
  public void onMessage(Message msg) {
  
                  Message response = session
                            .createTextMessage("Replying from server for "
                                    + m.getObject());
                    response.setJMSCorrelationID(msg.getJMSCorrelationID());
  
                  producer = session.createProducer(msg.getJMSReplyTo());
  
                  
                  producer.send(response);
                  
              }
  
      }
  }
  
  This listener is added to the server side consumer. The JMS server is  starded from a servlet, and here is the code where I use the above  class:
  
  public class ApplicationInit implements ServletContextListener {
    
  public void contextInitialized(ServletContextEvent e) {
    BrokerService jmsServer = new BrokerService();
  
  
                        jmsServer.addConnector("tcp://localhost:61615");
                        jmsServer.addConnector("tcp://localhost:61616");
                      jmsServer.start();
                       ActiveMQConnectionFactory factory  = new ActiveMQConnectionFactory(
                                "tcp://localhost:61615");
                       Connection conn =  factory.createConnection();
                      conn.start();
                       Session session =  conn.createSession(true,
                                Session.AUTO_ACKNOWLEDGE);
   
                      Queue queue = session.createQueue("SYNCHRONIZE");
                        MessageConsumer listener = session.createConsumer(queue);
                      
                        listener.setMessageListener(new AuditorSynchronizeListener(
                                session));
  }
    
}
  But when I start the client the following exception is thrown:
  
  javax.jms.JMSException: edu.emory.mathcs.backport.java.util.concurrent.TimeoutException
      at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.createJMSException(MultiplexingRequestor.java:205)
      at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:133)
      at org.logicblaze.lingo.jms.impl.MultiplexingRequestor.request(MultiplexingRequestor.java:95)
      at 
  Evicting inactive request for correlationID: Entry for key: 1
  
  in the client code:
  
  Queue messageQueue = session.createQueue("SYNCHRONIZE");
              MessageProducer producer = session.createProducer(messageQueue);
              producer.setTimeToLive(5000);
  
              Destination tempDest = session
              .createTemporaryQueue();
              MultiplexingRequestor multp = new MultiplexingRequestor(conn,
                       session, producer, messageQueue,  tempDest, true);
  
              Message msg = null;
          
              msg = session.createObjectMessage("Testing the client ");
              System.out.println("received =" +multp.request(messageQueue, msg));
  
James Strachan <ja...@gmail.com> wrote:  If you want to learn how to use the JMS API then Sun's JMS tutorial is
a pretty good start...

http://incubator.apache.org/activemq/how-do-i-get-started-with-jms.html

Alternatively you could stick to writing business level POJOs and hide
the middleware via Lingo which hides the JMS API from you letting you
focus on your business logic

http://lingo.codehaus.org/


On 10/3/06, Pico Florin 
 wrote:
> Hi, all!
>  I'm newbie in using the activemq API and I have some problems in  receiving a JMS message from a web server. Here is the scenario:
>  I have a reach client who sends JMS messages to a web server (Tomcat)  and it (the client) expects a reply from the server. I have read the  documentation related to this subject from here:
>     http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
>
>   but I'm a litlle bit confused because of this lines of code (bolded):
>
>   //server side
>
>  public void onMessage(Message request) { Message response =  session.createMessage();  response.setJMSCorrelationID(request.getJMSCorrelationID())  producer.send(request.getJMSReplyTo(), response) }
>   1. In this case who is the session and how can I obtain it?
>   2. Who is the producer and how can I obtain it?
>
>   On the client should I use the code:
>
>
>  // client side Destination tempDest = session.createTemporaryQueue();  MessageConsumer responseConsumer = session.createConsumer(tempDest);  ... // send a request.. message.setJMSReplyTo(tempDest)  message.setJMSCorrelationID(myCorrelationID); producer.send(message);
>   responseConsumer.receive(1000);
>
>   in order to receive the message?
>
>   Thank you,
>      Florin
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------
> Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail
>


-- 

James
-------
http://radio.weblogs.com/0112098/



 		
---------------------------------
 Inbox full of spam? Get leading spam protection and 1GB storage with All New Yahoo! Mail.

Re: Need simple example for receiving a JMS message

Posted by James Strachan <ja...@gmail.com>.
If you want to learn how to use the JMS API then Sun's JMS tutorial is
a pretty good start...

http://incubator.apache.org/activemq/how-do-i-get-started-with-jms.html

Alternatively you could stick to writing business level POJOs and hide
the middleware via Lingo which hides the JMS API from you letting you
focus on your business logic

http://lingo.codehaus.org/


On 10/3/06, Pico Florin <pi...@yahoo.co.uk> wrote:
> Hi, all!
>     I'm newbie in using the activemq API and I have some problems in receiving a JMS message from a web server. Here is the scenario:
>     I have a reach client who sends JMS messages to a web server (Tomcat) and it (the client) expects a reply from the server. I have read the documentation related to this subject from here:
>     http://activemq.org/site/how-should-i-implement-request-response-with-jms.html
>
>   but I'm a litlle bit confused because of this lines of code (bolded):
>
>   //server side
>
> public void onMessage(Message request) {      Message response = session.createMessage();    response.setJMSCorrelationID(request.getJMSCorrelationID())      producer.send(request.getJMSReplyTo(), response)  }
>   1. In this case who is the session and how can I obtain it?
>   2. Who is the producer and how can I obtain it?
>
>   On the client should I use the code:
>
>
> // client side  Destination tempDest = session.createTemporaryQueue();  MessageConsumer responseConsumer = session.createConsumer(tempDest);  ...    // send a request..  message.setJMSReplyTo(tempDest)  message.setJMSCorrelationID(myCorrelationID);    producer.send(message);
>   responseConsumer.receive(1000);
>
>   in order to receive the message?
>
>   Thank you,
>      Florin
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------
> Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with voicemail
>


-- 

James
-------
http://radio.weblogs.com/0112098/