Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused as to when you would use JMS (or a queue in general) versus a database

When you store a message in a queue, isn't it more of meta data information so whoever pulls from the queue knows how to process the data? the actual information in the queue doesn't always hold all the information.

Say you have an app like Twitter, whenever someone posts a message, you would still need to store the actual message text in the database correct?

The queue would be more used to broadcast to other subscribers that a new message has arrived, and then those services could take further action.

Or could you actually store the tweet text in the queue also? (or you COULD, but that would be silly?)

Could a queue message have status fields, which subscribers can change as they process their part of the work flow? (or would you do that in the db?)

Just trying to get some clarification of when you would use a queue versus db.

like image 725
mrblah Avatar asked Jan 08 '10 15:01

mrblah


People also ask

What is the difference between JMS queue and Topic?

Queues and Topics are similar when a sender sends messages, but messages are processed differently by a receiver. A queue can have only one consumer, whereas a topic can have multiple subscribers.

Why do we use JMS queue?

JMS supports both messaging models: point-to-point (queuing) and publish-subscribe. JMS was defined to allow Java application to use enterprise messaging systems. More importantly, it provides a common way for Java applications to access such enterprise messaging systems.

What is JMS queue?

JMS queue. A staging area that contains messages that have been sent and are waiting to be read (by only one consumer). As the name queue suggests, the messages are delivered in the order sent. A JMS queue guarantees that each message is processed only once.

What is the use of JMS in integration environment?

JMS is the standard messaging API for passing data between application components and allowing business integration in heterogeneous and legacy environments. JMS provides two programming models: Point-to-Point—Messages are sent to a single consumer using a JMS queue.


1 Answers

When a process wants to farm data and the processing of that data out to another process (possibly on a different host), there are 2 strategies:

  1. Stuff all your data into the queue item and let the receiving app worry about storing it in the database, among with whatever other processing.

  2. Update your database, and then queue a tiny message to the other process just to notify it that there's new data to be massaged.

There are a number of factors that can be used to decide on which strategy:

  • If your database is fully ACID (one would hope) but your queueing system (QS) is not, your data would be safer in the DB. Even if the queue message gets lost in a server crash, you could run a script to process unprocessed data found in the DB. This would be a case for option 2.

  • If your data is quite large (say, 1 MB or more) then it might be cruel to burden your QS with it. If it's persistent, you'll end up writing the data twice, first to the QS's persister and later to the DB. This could be a drag on performance and influence you to go for option 1.

  • If your DB is slow or not even accessible to your app's front end, then option 1 it is.

  • If your second process is going to do something with the data but not store it in a DB, then option 1 may be the way to go.

Can't think of any more, but I hope you get the idea.

like image 100
Carl Smotricz Avatar answered Nov 11 '22 09:11

Carl Smotricz