JBoss 5.1 - Chapter 05.0 - JMS
Jump to navigation
Jump to search
Messaging vs Method Call ⌘
Method Call | Messaging | |
---|---|---|
Implementation | Simple | Complex |
Coupling | Tight | Loose |
Caller knows destination | Yes | No |
Usually mode | Synchronous | Asynchronous |
Sample Implementations | RMI, RPC | JMS, ActiveMQ |
What is standardized | Destination Interface, Message Format |
Messaging Server Interface, Message Format |
JMS ⌘
- Vendor-neutral
- Java specific
- Well established and commonly used
- Multiple implementation, but compatible API
JMS Modes ⌘
- Point to Point (PtP or PTP)
- Publish/Subscribe
Point to Point ⌘
- Destination of the message is called a queue
- Producer -> Queue -> Consumer
- May have multiple receivers
- Once receiver consumes each message
- Once message has been consumed, it disappears from the queue
Publish/Subscribe ⌘
- Destination of the message is called a topic
- Message is send to all consumers who subscribed to a topic
- There may be multiple subscribers to the same topic
Subscription can be:
- Durable
- delivery is guaranteed
- message is received only once per subscriber
- Non-durable
- delivery is not guaranteed
- message can be received twice
- subscriber receives only those message that are published while the subscriber is active
Synchronous vs Asynchronous ⌘
- Synchronous
- Subscriber or a Consumer fetches the massage by calling receive() method
- The receive() method blocks until a message arrives or times out
- Asynchronous
- The client implements MessageListener interface
- When the message arrives, the Provider calls onMessage() method of the interface passing the content of the message
JMS Message structure ⌘
- Header
- Destination
- DeliveryMode
- MessageID
- Timestamp
- ....
- Properties
- Application related
- JMS Provider related
- STandard Properties
- Payload
JMS Delivery Mode ⌘
- Persistent (default)
- message saved in the database (in case of server shutdown)
- Non Persistent
- message can be lost
- increased performance