So given your requirement:

"Do you think I can process millions of message in single session? Could
there be any other option.
i have got, say 10 queue and 10 threads to process these incoming messages.
I have got one consumer for each queue (as queue would be different based on
the message type, so message type1 would go to queue1 and so on)"

I definitely would not create a new connection/session/consumer for each
message consumed.
Not sure how transactions would force you to do this (it's also not clear
what kind of transactional behavior you're needing here... transactions
when doing JMS stuff? or other XA stuff? )

A single session/consumer per queue (so 10 total) would handle your use
case just fine. Let me know if I missed something.


On Mon, Jan 28, 2013 at 4:48 AM, jainmanglesh
<[email protected]>wrote:

> Hi Christian,
>
> following is full snippet of code that I have (including thread creation
> and
> implemnetation of consumer code within run method):
>
> threads.add(new Thread() {
>         @Override
>         public void run() {
>                 try {
>                         Connection connection = connectionFactory
>                                         .createConnection();
>                         connection.start();
>                         // Create a Session
>                         Session session = connection.createSession(true,
> -1);
>                         Queue queue = session.createQueue(queueName);
>
>                         // Create a MessageConsumer from the Session to the
>                         // Topic or Queue
>                         MessageConsumer consumer = session
>                                         .createConsumer(queue);
>
>                         Message message = consumer
>                                                 .receive(10000);
>                         if (null != message) {
>
>                                 try {
>                                         //Get new transaction and perform
> action on message
>                                         //with help of listener.
>
> transactionManager.commit(transaction);
>                                 } catch (ActionException e) {
>                                         LOG.error(
>                                                         "Error on "
>                                                                         +
> getName()
>                                                                         +
> " when performing action. Pushing action to error queue.",
>                                                                         e);
>
> transactionManager.rollback(transaction);
>                                 } catch (Exception e) {
>                                         LOG.error(
>                                                         "Error on "
>                                                                         +
> getName()
>                                                                         +
> " when performing action. Pushing action to error queue.",
>                                                                         e);
>
> transactionManager.rollback(transaction);
>                                 }
>
>                         }
>                         }
>                         // Clean up
>                         consumer.close();
>
>                         //Below 2 lines creating exception
>                         session.close();
>                         connection.close();
>                 } catch (JMSException jmse) {
>                         LOG.error("Error while getting JMS connection");
>                 } catch (Exception e) {
>                         LOG.error("Error while processing event");
>                 }
>         }
> });
>
>
> The reason for using the above code is I need to have separate session for
> transactional purpose.
> I am getting events from system A to put in queue and then system B would
> consume them. to process them in sync I am doing one by one message in one
> session (as session are thread safe).
> I could have used only one connection and creating session/consumer for
> each
> message however I read somewhere (on forum) that there should be one to one
> mapping between connection and session.
>
> so I am creating connection/session/consumer for each message (which even I
> believe would be expensive in performance).
>
> Do you think I can process millions of message in single session? Could
> there be any other option.
> i have got, say 10 queue and 10 threads to process these incoming messages.
> I have got one consumer for each queue (as queue would be different based
> on
> the message type, so message type1 would go to queue1 and so on)
>
>
> The other thing is : when I try to close connection and session (in the
> above code), it throws exception that session already closed (probably when
> other thread tries to access same session) which i dont understand
> especially when I am creating new session for each thread execution.
>
>
> any help please
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/consumer-too-slow-to-process-messages-tp4662235p4662308.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



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

Reply via email to