activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jainmanglesh <jainmangl...@rediffmail.com>
Subject Re: consumer too slow to process messages
Date Mon, 28 Jan 2013 11:48:13 GMT
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.

Mime
View raw message