Message-Oriented Middleware (MOM) products like IBM MQ, MSMQ, and SonicMQ each had proprietary APIs. Developers had to rewrite code for each MOM vendor, creating vendor lock-in and forcing developers to learn multiple APIs.
JMS is a standard Java API for messaging that abstracts vendor-specific MOM implementations. You write code against the JMS API once, and plug in any compliant JMS provider (MOM implementation) without changing your code — similar to how JDBC abstracts database vendors.
- JMS API: Developer writes messaging code using standard JMS interfaces
- Service Provider Interface (SPI): JMS providers (like ActiveMQ, SonicMQ) implement the SPI to connect JMS API to their MOM product
- JNDI Lookup: Client looks up
ConnectionFactoryandDestinationfrom JNDI (administrator configures these) - Message Types: JMS supports TextMessage, BytesMessage, StreamMessage, ObjectMessage, and MapMessage
- Two messaging domains: Point-to-Point (Queues) and Publish/Subscribe (Topics) — each has its own interface flavor
- Standardized API — write once, run with any JMS provider
- Two separate interface flavors: PTP (
QueueConnection,QueueSession) and Pub/Sub (TopicConnection,TopicSession) - Core interfaces: ConnectionFactory, Connection, Session, Destination, Producer, Consumer
- MOM products provide guaranteed delivery, fault tolerance, load balancing
- Abstractions away low-level concerns: networking protocol, message format, server location
- Built from: MOM — JMS is an API abstraction over MOM products
- Builds into: MDB — MDBs consume JMS messages via
onMessage() - Related: JNDI — JMS uses JNDI to look up ConnectionFactory and Destination
- Contrasts with: RMI-IIOP — RMI is synchronous; JMS is asynchronous
- Related: JMS Programming Model — step-by-step process to send/receive messages
- JMS 1.0 had separate PTP and Pub/Sub interfaces; JMS 1.1 unified them (but EJB 2.x uses 1.0 style)
- Not all MOM features are exposed through JMS — some vendor-specific features need proprietary APIs
- JMS providers must be configured by administrator before application can use them
- ConnectionFactory and Destination must be looked up via JNDI — they are not created programmatically