You send these messages persistently and not transactionally. Which means that each sent message must be completed individually.
This means that for each message you send, you need to make a round-trip network on the server and wait for it to complete before you can send another message.
If you had several producers in this situation, hornetq will release both manufacturers, and you will save a lot of time. (that is, the server will execute many write requests).
If you want to expedite the dispatch of a single manufacturer, you should probably use transactions.
eg:
I - change the session to a transaction:
session = connection.createSession(true, Session.SESSION_TRANSACTIONED);
II - record all N messages:
for(int i=0;i<10000;i++){ messageSent++; publisher.send(message); if (messageSent % 1000 == 0) session.commit(); } session.commit();
You can also disable the synchronization of persistent messages. (Sending them asynchronously).
source share