Java Message Service

from Wikipedia, the free encyclopedia

Java Message Service ( JMS ) is a programming interface (API) for controlling a Message Oriented Middleware (MOM) for sending and receiving messages from a client , which is written in the Java programming language . JMS aims to enable loosely coupled, reliable and asynchronous communication between the components of a distributed application.

JMS is part of the Java Platform, Enterprise Edition ; the specification of the service and the associated API were standardized by the Java Community Process within the framework of JSR 914. The current version of JMS is version 2.0 from May 21, 2013 and is part of Java Enterprise Edition 7.0.

For the application you need a provider who implements the API and thus provides the service. There are both commercial products and open source projects for this.

functionality

Messaging is a possibility of loosely coupled and distributed communication in the form of messages sent between software components. Messaging tries to break the otherwise close coupling of other communication options such as TCP communication via sockets , CORBA or RMI by introducing a component located between the clients. This ensures that the clients do not have to have detailed knowledge of the remote station (s) of their communication, which increases the area of ​​application as well as the maintenance and reuse of the components.

JMS and driven by these services support two different approaches for sending messages, on the one hand, the message queue ( english queue ) for so-called point-to-point connections and the other a sign-dispatch system (Engl. Topic ) for publish-subscribe -Communication :

  • In the queue, the sender sends to a queue to which a recipient is attached. If no recipient is available, the message can optionally be saved and potential recipients can pick it up later at any time. In the case of only one recipient, this can best be compared with a parcel service. Each shipment has exactly one recipient. If they are not at home, they can pick up the shipment at any time later. If there are several recipients, when the messages are delivered, it is ensured that each queued message is assigned exactly once. This enables load balancing to be implemented, in which recipients can be added and removed as required.
  • In the registration dispatch system, the messages are sent to a topic to which any number of recipients listen. If the message is not consumed because no recipient has registered for the topic, then this is irrelevant. This can best be compared to a television station (broadcasting) . Either you turn on the TV and see the message, or you turn off the TV and don't see the message. Optionally, the messages can also be temporarily stored (durable subscription) .

implementation

In order to be able to send or receive messages, a queue or a topic must first be determined through which communication takes place. This is usually solved using a JNDI lookup:

Context ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
Queue myQueue = (Queue) ctx.lookup("MyQueue");

A connection is then created on which a session is started. Then, depending on whether sending or receiving, a transmitter or receiver is opened, via which messages can be sent or received:

QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(myQueue);
TextMessage message = session.createTextMessage();
sender.send(message);

or.

...
QueueReceiver receiver = session.createReceiver(myQueue);
connection.start();
Message message = receiver.receive();

Sending and receiving via topic is similar to sending and receiving via queue. There are on the one hand, other classes used ( TopicSession, TopicConnection, TopicPublisher, TopicSubscriber, Topic), on the other hand, one gets when receiving a message via Topic this means not receiver.receive()starting, but implements an MessageListener.onMessage(Message)event handler that the messages via Messagereceives events.

The different message types that can be sent via queues and topics are as follows:

Message
Message without content (body)
StreamMessage
Message containing a stream of Java primitives
MapMessage
Message with a map of Java objects
TextMessage
Message with a string (e.g. for XML messages)
ObjectMessage
Message with a serialized Java object
BytesMessage
Message with a stream of bytes

JMS provider

In order to be able to use JMS, a JMS provider is required that manages the topics, queues and sessions. The following is a list of JMS providers. It names both commercial and free software , but does not claim to be complete.

However, those JMS providers that are only offered as part of a Java EE container (Java application server ) are not listed. An overview of Java EE containers is available separately.

In the table below, the information contained in the "Operating modes" column means the following:

independent
The JMS provider runs as an independent process (stand alone) and therefore separate from the JMS client processes. Communication with the clients takes place, for example, via TCP / IP or Unix domain sockets .
embedded
The JMS provider runs in the same JVM (embedded, colocated) as one of the JMS clients. One advantage is the faster transmission of messages.

Modern JMS providers allow both operating modes.

Surname company License Operating modes Url
ActiveMQ Apache Open Source ( Apache 2 ) independent, embedded apache.org
FuseMQ Red hat Open source ( Apache 2 ), commercial support possible independent, embedded fusesource.com
Apollo Apache Open Source ( Apache 2 ) apache.org
FioranoMQ Fiorano commercially
iBus // MessageServer Softwired commercially
HornetQ (formerly known as " JBoss Messaging") Red hat Open Source ( Apache 2 ) independent, embedded jboss.org
JORAM OW2 Open Source ( LGPL ) independent, embedded ow2.org
MantaRay Coridan Open Source ( Mozilla Public License ) independent, embedded
Mom4j Mom4j development team Open Source (LGPL) embedded
MRG messaging Red hat commercially redhat.com
MuleMQ MuleSoft Inc. commercially mulesoft.com
OpenJMS Open source independent, embedded sourceforge.net
Open message queue Sun Microsystems Open source independent mq.java.net
Oracle Advanced Queuing (OAQ) Oracle commercially embedded oracle.com
Qpid Apache Open Source ( Apache 2 ) apache.org
SAP JMS SAP commercially embedded sap.com
SonicMQ Progress software commercially
SwiftMQ IIT software Open Source ( Apache 2 ) independent swiftmq.com
TIBCO Enterprise Message Service TIBCO commercially
webMethods Broker Software AG commercially independent, embedded softwareag.com
webMethods Universal Messaging Software AG commercially independent, embedded softwareag.com
Websphere MQ IBM commercially independent, embedded ibm.com
WSO2 message broker WSO2 Open Source ( Apache 2 ) independent wso2.com

Web links

Individual evidence

  1. J2EE: Java Message Service (JMS)
  2. Spec