Feeds

Programming message services in Java

Asynchronous interactions seem to be the way of the future

Beginner's guide to SSL certificates

What is a message service?

So what is a message service? A message service provides for distributed, loosely coupled communication between software components or applications. That is, it allows an application running on one host using one particular technology to communicate with another application running on another host, without the two clients needing to know anything directly about each other.

The communication is achieved by an intermediary, called the queue, on which a message can be placed, and from which messages can be read. As the intermediary is a queue, the general rule is that messages are read form the queue in a First In/First Out (or FIFO) manner.

Illustrates typical message queuing.

For example, in the above diagram (Figure 1), two message producers send messages to a queue. The queue sends the message onto the message consumer in a different thread of execution. Thus, the producers are not blocked while the consumer is processing the message. The messages may be held in the queue until the consumer is available to process them and delivery of the message to the consumer may be guaranteed (the promise of IBM’s MQ Series, for example, to deliver messages once and once only, was an important contribution to processing integrity when it first came out – Ed).

In addition, a message service may support many-to-one connections as above, or many-to-many as supported by the JMS topic concept. Both queues and topics can alter the order in which messages are retrieved using concepts such as priorities etc.

Implementing the producers and consumers

So, now we have the basic concepts of a message service, how do we use JMS to create producers and consumers of messages using the JMS API? To explore these concepts, I’ll step through the definition of a message producer and the implementation of an EJB3 based Message Driven Bean. Note that I could just implement a stand alone message consumer application, (it does not need to be an EJB) however, in my experience in a Java Enterprise Edition environment, it’s much more common to use an EJB for this; and EJBs make the whole process so much easier.

As the application server used to support our example, I’ll be using JBoss (in particular, I’m using JBoss 4.2.1) and the JBossMQ message service. Note that it’s also possible with JBOSS 4.2.1 to use the newer JBOSS Messaging JMS provider, which can give better performance than the older JBossMQ system and which replaces it entirely in JBoss 5.x. However, this requires some configuration and from a Java perspective it is hidden behind the façade of the JMS API.

Having sorted our message service provider, we can now consider the steps we must follow to create our JMS based application. These steps are presented below:

  1. Publish destinations (queues) using a server-specified mechanism. This can be done in JBoss using the JBossmq-destinations-service.xml file. Essentially this is a JNDI entry that is used to define a queue (or topic) as a destination.
  2. Define producers that generate messages.
  3. Define consumers that receive messages (note there is nothing to stop a client being both a producer and a consumer).
  4. Start the message server.
  5. Compile and start the producers and consumers.

We shall follow each of these steps below for a simple queue based application.

Beginner's guide to SSL certificates

More from The Register

next story
That dreaded syncing feeling: Will Microsoft EVER fix OneDrive?
Microsoft's long history of broken Windows sync
Mozilla, EFF, Cisco back free-as-in-FREE-BEER SSL cert authority
Let’s Encrypt to give HTTPS-everywhere a boost in 2015
SLURP! Flick your TONGUE around our LOLLIPOP – Google
Android 5 is coming – IF you're lucky enough to have the right gadget
Nokia's N1 fondleslab's HIDDEN BRILLIANCE: The 'Z Launcher'
Sugarcoating Android's Lollipop makes tab easier to swallow
Bug fixes! Get your APPLE BUG FIXES! iOS and OS X updates right here!
Yosemite fixes Wi-Fi hiccup, older iOS devices get performance boost
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
Meet Windows 10's new UI for OneDrive – also known as File Explorer
New preview build continues Redmond's retreat to the desktop
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Simplify SSL certificate management across the enterprise
Simple steps to take control of SSL across the enterprise, and recommendations for a management platform for full visibility and single-point of control for these Certificates.
Saudi Petroleum chooses Tegile storage solution
A storage solution that addresses company growth and performance for business-critical applications of caseware archive and search along with other key operational systems.