activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Posta <christian.po...@gmail.com>
Subject Re: How to setup multiple queues
Date Mon, 31 Dec 2012 18:43:26 GMT
So you don't need to have a separate session per queue (of course depending
on your requirements).
Also keep in mind that in your for loop, when you are "creating a queue"
it's not actually created on the broker until you use the queue (eg, create
a producer and send a message to the queue).

It might also be true for your case that you don't care to auto-create the
queues as they're needed and maybe you wish to have them created on the
broker side?


On Mon, Dec 31, 2012 at 3:29 AM, jainmanglesh
<jainmanglesh@rediffmail.com>wrote:

> Adding to that,
> I am able to create more than one queue with a for loop around session,
> destination.. like bwlo code:
>
>                         try {
>                                 // Create a ConnectionFactory
>                                 ActiveMQConnectionFactory
> connectionFactory = new
> ActiveMQConnectionFactory(url);
>
>                                 // Create a Connection
>                                 Connection connection =
> connectionFactory.createConnection();
>                                 connection.start();
>
>                                 for(int i = 0; i < 10; i++){
>                                         // Create a Session
>                                         Session session =
> connection.createSession(true,
> Session.AUTO_ACKNOWLEDGE);
>
>                                         // Create the destination (Topic
> or Queue)
>                                         Destination destination =
> session.createQueue("TEST.FOO" + i);
>                                         // Create a MessageProducer from
> the Session to the Topic or Queue
>                                         MessageProducer producer =
> session.createProducer(destination);
>
> //producer.setDeliveryMode(DeliveryMode.PERSISTENT);
>
>                                         // Create a messages
>                                         String text = "Hello world! From:
> " + Thread.currentThread().getName()
> + " : " + this.hashCode();
>                                         TextMessage message =
> session.createTextMessage(text);
>
>                                         // Tell the producer to send the
> message
>                                         System.out.println("Sent message:
> "+ message.hashCode() + " : " +
> Thread.currentThread().getName());
>                                         producer.send(message);
>
>                                         // Clean up
>                                         session.close();
>                                 }
>                                 connection.close();
>                         }
>                         catch (Exception e) {
>                                 System.out.println("Caught: " + e);
>                                 e.printStackTrace();
>                         }
>
>
> However I am not sure how the session for different queue will be
> distinguished (session and queue association).
>
> Even being a naive with activemq implementation, I am not sure (and doubt)
> if the above code is correct.
>
> Please help
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-to-setup-multiple-queues-tp3092113p4661190.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message