• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Messaging systems need to support different communication patterns: sometimes you want one-to-one delivery (like a personal SMS), and sometimes one-to-many broadcast (like a radio station). Without distinct models, the messaging API would be ambiguous about delivery semantics.

Core Idea

JMS defines two messaging domains: Point-to-Point (PTP) uses Queues for one-to-one delivery (each message consumed by exactly one receiver), while Publish/Subscribe (Pub/Sub) uses Topics for one-to-many broadcast (each message delivered to all subscribers).

How It Works

Point-to-Point (Queue)

  1. Producer sends message to a Queue destination
  2. Message stays in queue until a Consumer receives it
  3. Each message is consumed by exactly one consumer (even if multiple consumers are listening)
  4. If no consumers are available, message remains in queue until one connects

Publish/Subscribe (Topic)

  1. Publisher sends message to a Topic destination
  2. All active Subscribers registered to that topic receive the message
  3. Each subscriber gets its own copy of the message
  4. Durable subscribers can receive messages even if they were offline (messages persisted)

JMS Interface Mapping

InterfacePTP (Queue)Pub/Sub (Topic)
ConnectionFactoryQueueConnectionFactoryTopicConnectionFactory
ConnectionQueueConnectionTopicConnection
SessionQueueSessionTopicSession
DestinationQueueTopic
ProducerQueueSenderTopicPublisher
ConsumerQueueReceiverTopicSubscriber

Visual Explanation

G cluster_ptp Point-to-Point (Queue) cluster_pub Publish/Subscribe (Topic) P1 Producer A Q Queue P1->Q C1 Consumer 1 Q->C1 msg goes to one only C2 Consumer 2 Q->C2 waits P2 Publisher T Topic P2->T S1 Subscriber 1 T->S1 msg to all S2 Subscriber 2 T->S2 msg to all

Key Properties

  • PTP: Guarantees exactly-once delivery to a single consumer; good for load balancing work across consumers
  • Pub/Sub: Broadcasts to all subscribers; good for event notification, news feeds
  • PTP Queue messages persist until consumed; Pub/Sub Topic messages only go to active subscribers (unless durable)
  • Same JMS code structure, different interface types for each domain
  • EJB MDBs can listen to either Queues or Topics

Connections

  • Built from: JMS — these are the two JMS messaging domains
  • Built from: JMS Programming Model — the model applies to both PTP and Pub/Sub
  • Builds into: MDB — MDBs consume from either Queues or Topics
  • Related: Queue Partitioning — using multiple queues for traffic separation
  • Contrasts with: RMI-IIOP — RMI is always 1:1, messaging offers both 1:1 and 1:N

Edge Cases & Gotchas

  • Pub/Sub with no active subscribers means messages are lost (unless durable subscriptions)
  • PTP with multiple consumers: you can’t predict which consumer gets which message
  • Mixing Queue and Topic interfaces (e.g., using QueueSender with a Topic) causes runtime errors
  • Durable subscribers in Pub/Sub must be explicitly created and have a unique client ID