Search the Web for JAVA Answers:

Search the Web for more JAVA Answers:
Hint: Press Ctrl+ to increase the font size of this blog and Ctrl- to decrease the font size of this blog.

JMS Answers

Click Here for a tutorial on Java Messaging Services.

1. How may messaging models does JMS provide for and what are they?
Answer: The Java Message Service (JMS) API is a messaging standard that allows application components based on the Java 2 Platform, Enterprise Edition (J2EE) to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.

JMS provide for two messaging models: publish-and-subscribe and point to-point queuing.
-----------------------------------------------------------------
2. What is messaging?
Answer: Messaging is a mechanism by which data can be passed from one application to another application.
-----------------------------------------------------------------
3. What is point-to-point messaging?
Answer: With point-to-point message passing the sending application/client establishes a named message queue in the JMS broker/server and sends messages to this queue. The receiving client registers with the broker to receive messages posted to this queue. There is a one-to-one relationship between the sending and receiving clients.
-----------------------------------------------------------------
4.  Can two different JMS services talk to each other? For instance, if A and B are two different JMS providers, can Provider A send messages directly to Provider B? If not, then can a subscriber to Provider A act as a publisher to Provider B?
Answer: The answers are NO to the first question and YES to the second.

The JMS specification does not require that one JMS provider be able to send messages directly to another provider. However, the specification does require that a JMS client must be able to accept a message created by a different JMS provider, so a message received by a subscriber to Provider A can then be published to Provider B. One caveat is that the publisher to Provider B is not required to handle a JMSReplyTo header that refers to a destination that is specific to Provider A.
-----------------------------------------------------------------
5. What is the advantage of persistent message delivery compared to non-persistent delivery?
Answer: If the JMS server experiences a failure, for example, a power outage, any message that it is holding in primary storage potentially could be lost. With persistent storage, the JMS server logs every message to secondary storage. (The logging occurs on the front end, that is, as part of handling the send operation from the message producing client.) The logged message is removed from secondary storage only after it has been successfully delivered to all consuming clients.
-----------------------------------------------------------------
6. How is a java object message delivered to a non-java Client?
Answer:  It is according to the specification that the message sent should be received in the same format. A non-java client cannot receive a message in the form of java object. The provider in between handles the conversion of the data type and the message is transferred to the other end.
-----------------------------------------------------------------
7.  What is MDB and what is it special?
Answer:  MDB is Message driven bean, which very much resembles the Stateless session bean. The incoming and out going messages can be handled by the Message driven bean. The ability to communicate asynchronously is the special feature about the Message driven bean.
-----------------------------------------------------------------
8. Give an example of using the publish/subscribe model.
Answer: JMS can be used to broadcast shutdown messages to clients connected to the Weblogic server on a module wise basis. If an application has six modules, each module behaves like a subscriber to a named topic on the server.
-----------------------------------------------------------------
9. What is the difference between the Mailing and Messaging?
Answer: Java Mailing is the set of APIs that primarily concerns with the sending of Mail messages through the standard mail protocols. Messaging is the way of communicating to the remote machines using Message Oriented Middlewares. Message Oriented Middlewares do not use mailing internally for communication. They create their own channels for communication.
-----------------------------------------------------------------
10. What are the types of messaging?
Answer: There are two kinds of Messaging.
Synchronous Messaging:
Synchronous messaging involves a client that waits for the server to respond to a message.
Asynchronous Messaging:
Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server.
-----------------------------------------------------------------
11. What is publish/subscribe messaging?
Answer: With publish/subscribe message passing the sending application/client establishes a named topic in the JMS broker/server and publishes messages to this queue. The receiving clients register via the broker to messages by topic; every subscriber to a topic receives each message published to that topic. There is a one-many relationship between the publishing client and the subscribing clients.
-----------------------------------------------------------------
12. Why doesn't the JMS API provide end-to-end synchronous message delivery and notification of delivery?
Answer: Some messaging systems provide synchronous delivery to destinations as a mechanism for implementing reliable applications. Some systems provide clients with various forms of delivery notification so that the clients can detect dropped or ignored messages. This is not the model defined by the JMS API.

JMS API messaging provides guaranteed delivery via the once-and-only once delivery semantics of persistent messages. In addition, message consumers can insure reliable processing of messages by using either CLIENT_ACKNOWLEDGE mode or transacted sessions. This achieves reliable delivery with minimum synchronization and is the enterprise messaging model most vendors and developers prefer.
The JMS API does not define a schema of systems messages (such as delivery notifications). If an application requires acknowledgment of message receipt, it can define an application-level acknowledgment message.
-----------------------------------------------------------------
13. What are the core JMS-related objects required for each JMS-enabled application?
Answer: Each JMS-enabled client must establish the following:
- A connection object provided by the JMS server (the message broker).
- Within a connection, one or more sessions, which provide a context for message sending and receiving.
- Within a session, either a queue or topic object representing the destination (the message staging area) within the message broker.
- Within a session, the appropriate sender or publisher or receiver or subscriber object (depending on whether the client is a message producer or consumer and uses a point-to-point or publish/subscribe strategy, respectively).
-Within a session, a message object (to send or to receive).
-----------------------------------------------------------------
14. What are the various message types supported by JMS?
Answer:
-Stream Messages: Group of Java Primitives
-Map Messages: Name Value Pairs.
-Name being a string
-Value being a java primitive
-Text Messages:  String messages (since being widely used a separate messaging Type has been supported)
Object Messages:  Group of serialize able java object
Bytes Message: Stream of uninterrupted bytes.
-----------------------------------------------------------------
15.  What is the role of the JMS Provider?
Answer: The JMS provider handles security of the messages, data conversion and the client triggering. The JMS provider specifies the level of encryption and the security level of the message, the best data type for the non-JMS client.
-----------------------------------------------------------------
16.  How does a typical client perform the communication?
Answer:
1. Use JNDI to locate administrative objects.
1a. Locate a single ConnectionFactory object.
1b. Locate one or more Destination objects.
2. Use the ConnectionFactory to create a JMS Connection.
3. Use the Connection to create one or more Session(s).
4. Use a Session and the Destinations to create the MessageProducers and MessageConsumers needed.
5. Perform your communication.
-----------------------------------------------------------------
17.Give an example of using the point-to-point model.
Answer: The point-to-point model is used when the information is specific to a single client. For example, a client can send a message for a print out, and the server can send information back to this client after completion of the print job.
-----------------------------------------------------------------
18. Question How does the application server handle the JMS Connection?
Answer:
- Application server creates the server session and stores them in a pool.
- Connection consumer uses the server session to put messages in the session of the JMS.
- Server session is the one that spawns the JMS session.
- Applications written by application programmers creates the message listener.