0

I have an application with a high level of load and performance's critical .

Now, I'm migrating the application to use EJB. I'm very worried about using EJB to consume messages on queues because transactionality can decrease the performance.

Now, I'm consuming X messages in the same transaction, but I don't know how do the same using MDBs. Is it possible to consume a block of messages in an MDB using only one transaction?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Unless the transaction causes some contention somewhere (such as performing some kind of database operation and waiting for locks) then network latency during message delivery will swamp the overhead of executing within a transaction. – Steve C Mar 20 '17 at 13:54

1 Answers1

0

It is not guaranteed that the same MDB will process the stream of messages.

I think you can achieve what you want by using a stateless bean with an @Asynchronous invocation, and passing your set of messages.

Something like that:

@Stateless
public class AsynchProcessor {

   @Asynchronous
   public void processMessages(Set<MyMessage> messages) {....}

}

Decorate your method with Future if necessary, then in your client.

Set<MyMessage> messages = ...
asynchProcessor.processMessages(messages)
Leonardo
  • 9,607
  • 17
  • 49
  • 89
  • The same could be achieved if an item in the queue contained a set instead of a single item. There are a lot of things to consider when choosing MDBs vs '@Asynchronous' i.e loss of data in case of application crash. – garfield Mar 19 '17 at 07:18
  • That's an option too. MDB are more reliable in case of redelivery. It depends on what the design is. Another possible option is to invoke a programmatic persistent timer from @Asynchronous. Of course this has downside effect to consider. – Leonardo Mar 19 '17 at 13:43
  • Thanks for your replies. The problem is I need to process between 1 to 2000000 of messages in a single transaction, the amount depends of client. For this reason, if aclient sent me 2000000 of messages, I can't manage all in a single call with a list parameter. Surely I would have memory problems. I'm looking for Wildfly something like Oracle MDB Transaction Batching (https://docs.oracle.com/cd/E23943_01/web.1111/e15493/batching.htm#WLMDB460) I will continue looking for a solution, but if you could help me I would be grateful. – José Miguel Mar 20 '17 at 18:53
  • Uhm...200000 messages are quite a lot. The safest thing I can think about if the message are not big, right now is to save messages to database and assign them a group, then send a message to an MDB with the group to process. The MDB will do the rest, and lately will clean the table. – Leonardo Mar 22 '17 at 14:38