Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Sort ObjectMessage in Queue.

linkin
Member Posts: 423
Hi,
Publisher send some ObjectMessage(any pojo) in to the queue. let there are 5 message in queue.
When Consumer is wake up it reads the queue and sort all the queue objects (on the basis of some property of pojo class i.e entry_date, priority_level) and pick the top one and process and leave the rest in to the queue. And do the above thing again and again until the queue is empty.
So my question is that is it possible to implements?if yes the give some way.
Thanks & Regards
Publisher send some ObjectMessage(any pojo) in to the queue. let there are 5 message in queue.
When Consumer is wake up it reads the queue and sort all the queue objects (on the basis of some property of pojo class i.e entry_date, priority_level) and pick the top one and process and leave the rest in to the queue. And do the above thing again and again until the queue is empty.
So my question is that is it possible to implements?if yes the give some way.
Thanks & Regards
Answers
-
Publisher send some ObjectMessage(any pojo) in to the queue. let there are 5 message in queue.You can't in general consume arbitrary messages from the middle of a queue. It's a queue and is designed for messages to be delivered in order.
When Consumer is wake up it reads the queue and sort all the queue objects (on the basis of some property of pojo class i.e entry_date, priority_level) and pick the top one and process and leave the rest in to the queue. And do the above thing again and again until the queue is empty.
So my question is that is it possible to implements?if yes the give some way.
However the JMS "message selector" feature may be worth investigating. This allows you to define a filtered view of the queue on the basis of various message header properties. Please consult any JMS textbook or your product documentation for more information.
Nigel -
nigeldeakin wrote:The OP does specifically state taking from the top of the queue, not "in the middle" as you suggest. I think the basic question is how to sort messages on the queue and only process one message at a time. Consuming messages synchronously seems a solution to the latter requirement, like this basic tutorial demonstrates:
You can't in general consume arbitrary messages from the middle of a queue.
http://java.sun.com/developer/technicalArticles/Ecommerce/jms/
But that does not cover sorting. I'm not too familiar with JMS at that level, but I believe that is something that would be a vendor specific feature and in general not a good requirement to have when messaging is involved. The power of the system is in the ability to deal with messages in any order, synchronously or asynchronously. -
gimbal2 wrote:If the OP wants to change the order of messages on a queue prior to consuming them then this isn't a feature provided by JMS.nigeldeakin wrote:The OP does specifically state taking from the top of the queue, not "in the middle" as you suggest. I think the basic question is how to sort messages on the queue and only process one message at a time. Consuming messages synchronously seems a solution to the latter requirement, like this basic tutorial demonstrates:
You can't in general consume arbitrary messages from the middle of a queue.
http://java.sun.com/developer/technicalArticles/Ecommerce/jms/
But that does not cover sorting. I'm not too familiar with JMS at that level, but I believe that is something that would be a vendor specific feature and in general not a good requirement to have when messaging is involved. The power of the system is in the ability to deal with messages in any order, synchronously or asynchronously.
Nigel -
Not by the specification, no. But there are multiple implementations out there with vendor specific features. Perhaps something can be found there, but that doesn't change the fact that it is probably not a good idea to need something like that. It smells like an architectural mistake.
-
I find it pretty hard to believe that any vendor would supply an operation that sorted a queue in situ. What happens if another message arrives during the sort? or after the sort but before the client takes off the first message? It just cannot work correctly, because it can't be atomic.
The OP should be using a message filter as suggested earlier. -
Well, it would just require inserting new objects into the right place into the queue, which is hardly "sorting". But yeah, it would have to lock out both reads by consumers and writes by producers while it was doing that insertion.
However I find it hard to believe that any vendor would provide this feature strictly for ObjectMessages and allow comparison based on properties of the enclosed objects. Sounds too unlikely for even the IBMs of the world to contemplate. -
No, the OP is talking about sorting existing messages in situ, not ordered insertion. It was suggested that a vendor might provide such a thing. I don't believe it is even feasible let alone desirable.
Maybe the OP should just reconsider (or consider) his notion of queue priority. -
EJP wrote:In partial defense, I base my hasty conclusions on a Google search pointing at JBoss messaging implementations that can do at least some form of sorting, but I didn't investigate through to actually be able to claim that what I found relates in any way to this thread. My main point was to investigate implementation specific features when you need to do something that the API doesn't provide.
No, the OP is talking about sorting existing messages in situ, not ordered insertion. It was suggested that a vendor might provide such a thing. I don't believe it is even feasible let alone desirable. -
Thanks all of you.
Thanks & Regards
This discussion has been closed.