In the first one, the components know each other, i.e who is the sender and who is the receiver.So they communicate direclty. Examples for this kind of communication are CORBA,RMI, TCP n/w sockets.
In the second type of communication,i.e the lightly coupled communication, there is an intermediate component coming in between the communicating entities. So the sender and receiver do not communicate directly, instead they use another entity in between.
JMS falls in the second category. It is java's standard for Message Oreinted Middleware (MOM) service which is essential in enterprise applicaton.
It should be notee that, just like any other j2ee specification, JMS is onlya standard for messaging. The vendors would provide this service. But the components which intend to usethis service can call the standard interfaces to get their work done, without least bothering about how the implementation is done.
All Java EE application servers from version 1.4 and later are required to contain a JMS provider.
Following entities are conceptualized.
JMS provider --- this is the one which provides messaging service
JMS clients ---- these are entities which produce and consume messages
Messages ---- information is sent and received as messages
Messaging can be done in 2 ways.
1.Point to point (PTP)
2.Publish and subsribe(Pub/Sub)
Here comes the interesting part.
In PTP, there is a client which wants to send a message to another client. It would put it in an entity called "queue" meant for the intended client. The client might be off when the message was put in its queue. But when client wakes up and checks its queue, it would get its message and send an acknowledgement back.Here every message is sent to the queue of the intended client separately. Or only one client is supposed to receive the message sent. It can be imagined as a postman putting the letter in the post box attached to the door of the clien't house. PTP messaging is used when every message sent must be processed by one consumer.
In the Pub/Sub model, there is a particular topic on which interested clients can publish messages or subscribe for messages. Here normally neither publishers nor the subscribers know each other.The message provider would take care of sending the messages belonging to a particular topic coming from multiple publishers to multiple subscribers. Once the messages are sent to all the concerned subscribers, the particular message in the topic is not retained.
Pub/sub messaging is used when each message can be processed by zero,or many consumers.
Each JMS provider would have a JNDI name. Any java class can connect to any JMS provider using the JNDI info for that. It would further use the ConnectionFactory to get the connection to a particular Topic or Queue.
Following are the important concepts (interfaces)
1.ConnectionFactory - You ask for a connection by specifying its JNDI name and this will give you. The connection could be to a topic or queue. The corresponding connection factory can be used.
2.Connection --If you have the Connection means you have established a communication with the JMS message provider product and you can start doing what all you want - it could be creating session, sending a message or receiving a message to and from a queue or topic. Again we have corresponding connection objects for queue and topic
3.Destination - This represents an entity where the messages are supposed to reach. It could be a queue or a topic accordingly.
4.Message Consumer -- This entity eats up the message sent to it. In case of Queue it is QueueReceiver and in case of Topic it is TopicSubsciber(Note that this is different from Destination in the sense, destination represents where a message should reach and stay, the consumer is the one who grabs the message sitting there in the destination)
5.MessageProducer -- This is the one that generates the message and sends it to the destination (Queue or Topic). We have accordingly QueueSender and TopicPublisher.
6.Message - this is the entity which actually moves here and there.It could be textmessage,bytemessage,stream message etc.
7.Session -- Represents context for sending and receiving the messages.
Represents a single-threaded context for sending and receiving messages. A session is single-threaded so that messages are serialized, meaning that messages are received one-by-one in the order sent. The benefit of a session is that it supports transactions. If the user selects transaction support, the session context holds a group of messages until the transaction is committed, then delivers the messages. Before committing the transaction, the user can cancel the messages using a rollback operation. A session allows users to create message producers to send messages, and message consumers to receive messages.
http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/basics.htmlhttp://en.wikipedia.org/wiki/Java_Message_Service
0 comments:
Post a Comment