Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Order of Messages in JMS  RSS feed

 
Ranch Hand
Posts: 381
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose a producer adds the messages 1,2,3,4,5... in a queue, then what will be the order in which the consumer gets these messages? Will it always be FIFO order i.e. 1,2,3,4,5..?
 
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, JMS is a wrapper layer on top of the messaging environment, so, to answer your question... it depends on implementation that you are using.

Anyway, for a few of the messaging environments (and configurations) that I used, the answer would be "no". It is possible for a consumer to skip messages, as those messages were delivered to other consumers. And it is possible for a consumer to get an earlier message, than the previous, as it is possible for a consumer to fail, timeout, and the messages that it took with it, has to be redelivered to other consumers.

Henry
 
Vaibhav Gargs
Ranch Hand
Posts: 381
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry. Suppose we have a single producer and single consumer for a queue, then, will it receive the messages in the publishing order. Let us assume ActiveMQ, IBMMQ is being used.
 
Saloon Keeper
Posts: 2260
289
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Community > FAQ > Using Apache ActiveMQ > How do I preserve order of messages:

ActiveMQ will preserve the order of messages sent by a single producer to all consumers on a topic. If there is a single consumer on a queue then the order of messages sent by a single producer will be preserved as well.

If you have multiple consumers on a single queue the consumers will compete for messages and ActiveMQ will load balance across them, so order will be lost. For background on the issue and how it can be solved see

  • Exclusive Consumer which allows only a single consumer to consume from the queue at once to preseve order
  • Message Groups which splits the messages on a queue into parallel virtual exclusive queues to ensure that messages to a single message group (defined by the JMSXGroupID header) will have their order preserved but that different groups will be load balanced to different consumers.
  •  
    Don't listen to Steve. Just read this tiny ad:
    Programmatically Create PDF Using Free Spire.PDF with Java
    https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!