1) How is this possible???
Its not, the caveat being with redelivery.
2) What determines the delivery sequence?
Is it the moment where the message is put on the queue or is it the moment when the queue session is committed???
messages are added to the queue in the order they are sent by a producer, a consumer consumes from a queue in the order they are in the queue
Both receive processes are in separate threads.
This could be your issue, firstly you shouldnt have multiple threads using the same session at the same time, also you are probably introducing some non deterministic behaviour, also remember messages are buffered by the consumer.
Thanks for your response.
We are not sharing the same session between threads. This is the code that handles the incomming messages:
Session session = null;
PooledQueueSession pooledQueueSession = null;
Transaction databaseTx = null;
session = getSessionFactory().openSession();
databaseTx = session.beginTransaction(); // start the database transaction
Set<DeliveryServiceData> destinations = determineDestinations(message.getOperation(),namespace.getNamespaceUrl(),message.getSender(), message.getDestinations());
pooledQueueSession = client.getPooledQueueSession();
for (DeliveryServiceData destination : destinations)
client.storeMessageOnQueue(namespace, session, pooledQueueSession, message.getXmlAsStringMessage(), response, destination.getQueueName(), destination.getReceiver(), message.getOperation(), message.getMessageId());
throw new RuntimeException("No valid destination found to deliver messages check broker configuration for destination: " + message.getDestinations());
databaseTx.commit(); // commmit the database
pooledQueueSession.commit(); //commit the queues
catch (Exception e) ....
We do have multiple threads that recieve messages but each thread is using a queueSession from a "queueSessionPool", so each thread has its own session. In that session it could however put messages in the same queue.
That's why I was wondering: what determines the position of the message in a queue, is it the Put method or is it the commit of the session.??
So in case of :
thread1 put msgx in queue A
thread2 put msgY in queue A
Would the mesasage be consumed from the queue A in the order or msgx, msgy or msgy, msgx ?? I think that's the big question here.
The message arrives at the queue when it is commited, but remember ordering is point to point, i.e. between 1 producer and 1 consumer, so even when you think messages are out of order they probably arent. Basically you can't determine order between multiple producers and consumers.
Ok Andy thanks. Your answers are helping me.
Also, notice that the message will be on a client buffer if you are not consuming all the messages on a buffer.
If you have a slow consumer, or if you are opening a consumer just to close it after received the message, you should set the consumerWindowSize=0 to disable client buffering. (that will have performance implications, as your throuhgput of messages will be maximized by your network lattency since you will need to send a packet from the client to receive a message from the server).