• Post Reply Bookmark Topic Watch Topic
  • New Topic

schedule commit for session_Transacted

 
Hari Babburi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
like to have session commit based on time.


Suppose my batch size is 100 and I have received so far 90 message, unless I have received 100 messages my session will not commit. to avoid that I like to have commit after a specific duration. I am using MessageListener to consume messages. is there any way to achive this without any problem if we receive message, while doing scheduled commit


my onMessage methof of Messagelistener is as follows

public void onMessage(Message message) {
log.info("onMessage Start");
messageCount++;
boolean result = processMessage(message);
if(result) {
if(ackRequired) {
try {
message.acknowledge();
} catch (JMSException e) {
log.info("Unable to ack meesage on " + receiver.getDestinationName(), e);
rollback();
}
}
if(transacted && (messageCount >= batchSize)) {
completeTransaction();
}
}
log.info("onMessage end");
}

i want to get called completeTransaction if there is no message for a specified time and messageCount hasn't reached to batchSize
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Message Driven Bean (MDB) for consuming messages. This also implements Message Listener, and onMessage() method. The transaction hadling is now taken care by the EJB container.

On the other way you can commit the things after processing every message.
Understand the message Listener creates a thread for each message its consuming.
 
Hari Babburi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prabhakar,
Thanks for the Info.
I am not using EJB Server. It is a plain java application. I don't want to commit on each message due to performance reason. That is the reason to choose Session_Transacted

Hari
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!