Christophe Herreman, a Java developer from Belgium made the following twit today:
“At the supermarket, and I once again seem to have picked the wrong lane… I wonder if there is a strategy for this. rdquo;
Being a member of the Java community myself, I feel obligated to offer my approach to making this very important decision that every Java developer has to make on a weekly basis.
First, I need to make a statement: out of all APIs I like Java Message Service (JMS) the most. IMO, JMS is the right way of architecting loosely coupled and reliable distributed applications. I explained this five years ago in the fifth article of my dissertation titled “Yakov “s Gas Station “. BTW, last week, I joined a project at a financial company and was pleasantly surprised learning that the trading application was build using just JMS, JNDI, and JDBC without the use of any other frameworks.
Now let “s go back to the supermarket scenario, and I “ll show how the understanding of messaging concepts can help you in picking the right lane.
1. In message-oriented middleware (MOM), messages are being placed into queues (think food items placed on the moving belt at the cash register).
2. In MOM systems we create message listeners that have to drain the queues and process messages (have to pick the items from the belt and scan their bar codes).
3. Ideally, the message queue (the belt) has to be empty ndash; each object put in the queue is immediately picked up by the listener. But in a real world, the speed of adding messages to the queue (placing items on the belt) may be higher than the speed of draining the queue. In this case we can add another listening thread or increase the size of the pool of Message-driven beans if a Java EE sever is in use.
4. The number of people (message senders) waiting in lines to each cash register (a queue) in a crowded supermarket is about the same. The message load (the number of items in the baskets) is also similar.
5. So what become the most important in the entire process? You got it – the speed of draining the queue.
Here “s comes the answer: picking the lane with the faster message listener is the holly grail of the consumer “s decision at a supermarket.
Christophe, the next time you are going to do your food shopping, spend about 30 seconds watching the cash register workers, and then pick the lane with the fastest one. As simple as that.
Actually, you need to know about yet another important messaging term, so-called poison messages. Say, your JMS listener is expecting only text messages, but for some reason a message of a different type (or the corrupted one) got into this queue (e.g. an item without the bar code). Then the process will become dependent on how efficiently such exceptional situation is being processed. In messing systems you can attempt a certain number of the redelivery attempts, and if this won “t help, the message goes into a dead-letter queue. In the supermarket they call the manager. Unfortunately, even I can “t predict in which basket the item without the bar code is located or which customer is planning to engage into a fight proving to the cashier that her expired cereal coupon should be accepted anyway.
I hope this life hack will save time to millions of Java developers, most of whom work for food these days. If you are not familiar with the Java messaging, I highly recommend to purchase my latest book Java Programming. 24-Hour Trainer, where I explain MOM and JMS in the lesson 30. Sorry for the shameless plug.
Enjoy your next shopping!