Objective 9.1: Identify scenarios that are appropriate to implementation using messaging, EJB, or both
Messaging is a way for software components to communicate. It is loosely coupled in that the sender does not need to know about the receiver and vice-versa. The only contract is the format of the message. In fact the sender and receiver do not even have to be available at the same time.
Generic API on top of a MOM (Message Oriented Middle-ware, eg: MQSeries) layer in the same way as JDBC is on top of SQL for RDBMS. Also, it supports asynchronous messaging and the aim to delivery once and only once (reliability). Found in package javax.jms.*
When to:
- Use for performance; stick on queue and reply, no blocking for lengthy processing.
 - Smooth load balancing; the least busy machine will ‘pull’ the message from the queue.
 - Integrate with legacy system that uses a MOM.
 - Parallel processing by launching a number of messages and continue.
 - Need reliable asynchronous communication.
 
When no to:
- When your not sure the operation will succeed, can’t throw exceptions.
 - When you need to return a value.
 - When you want a ‘simple’ system; a MOM is less manageable.
 
- EJB and Web Container objects can send and receive synchronous JMS messages.
 - EJB and Web Container objects can create asynchronous JMS messages.
 - EJB Container supports Message Driven EJBs for receiving asynchronous messages.
 - The sending and receiving can participate in distributed transactions and concurrent consumption of messages. That is, when you commit a message is guaranteed to be delivered, if the business logic fails on the consumer side is another matter.
 
- JMS Provider – system that implements the interfaces, the MOM.
 - JMS Clients – Java producers and consumers of messages.
 - Native Clients – non-Java producers and consumers of messages.
 - Messages – objects passed between clients, there are various types, TextMessage, BytesMessage, MapMessage, etc.
 - Point-to-point messaging – one consumer of a message, no timing dependancies between the client and server, consumer acknowledges the message has been consumed.
 - Publish-Subscribe – producer publishes (sends) messages to a ‘topic’. Consumers subscribe to the topic to receive the messages. There can be multiple publishers and subscribers. One message can be sent to many consumers. The producer and consumer have a timing dependancy – the producer must remain alive until the consumers have consumed.
 - Publish-Subscribe with durable subscriptions – as above but allows the producer to not be alive whilst they are being consumed, thus more flexible.
 - Destination Factory – administered by J2EE and found via JNDI, accessed by generic vendor neutral interfaces, used to specify a target for messages (queue or topic name).
 - Connection Factory - administered by J2EE and found via JNDI, accessed by generic vendor neutral interfaces, used to create a connection to a JMS provider (the MOM and type of, eg: queue or topic).