Answers

Question and Answer:

  Home  BEA Weblogic

⟩ Is it possible to set aside a message and acknowledge it later?

There are no special primitives for doing this. Here are two possible solutions.

One approach is to use multiple sessions as in the following:

while (true) {

Create a session, subscribe to one message on durable

subscription

Close session

Save session reference in memory

To acknowledge the message, find the session reference and call

acknowledge() on it.

}

Another solution is to use transactions and suspend the work as follows:

start transaction

while(true) {

message = receive();

if (message is one that I can handle)

process the message

commit

} else {

suspend transaction

put transaction aside with message

start transaction

}

}

To "acknowledge" the message:

resume user transaction

commit

To "recover" the message:

resume user transaction

rollback

Each time you suspend, you need to push the transaction onto a stack or list possibly with the message so you can process it or roll it back later. This solution is high overhead in that there can be a large build up of outstanding transactions. Note that transactions have timeouts and it may rollback on its own, which means you can get the message again (in a different transaction). Note also that there are some practical limits on the number of transactions you should leave outstanding. The default limit is something like 10000. Eventually you want to go back to your stack/list and commit/rollback the transactions. Note that transaction references (javax.transaction.Transaction) are not Serializable.

 208 views

More Questions for you: