Questo contenuto non è disponibile nella lingua selezionata.

Chapter 7. Senders and receivers


The client uses sender and receiver links to represent channels for delivering messages. Senders and receivers are unidirectional, with a source end for the message origin, and a target end for the message destination.

Sources and targets often point to queues or topics on a message broker. Sources are also used to represent subscriptions.

7.1. Creating queues and topics on demand

Some message servers support on-demand creation of queues and topics. When a sender or receiver is attached, the server uses the sender target address or the receiver source address to create a queue or topic with a name matching the address.

The message server typically defaults to creating either a queue (for one-to-one message delivery) or a topic (for one-to-many message delivery). The client can indicate which it prefers by setting the queue or topic capability on the source or target.

To select queue or topic semantics, follow these steps:

  1. Configure your message server for automatic creation of queues and topics. This is often the default configuration.
  2. Set either the queue or topic capability on your sender target or receiver source, as in the examples below.

Example: Sending to a queue created on demand

  SenderOptions senderOptions = new SenderOptions();
  senderOptions.targetOptions().capabilities("queue");
  Sender sender = connection.openSender(address, senderOptions);
Copy to Clipboard Toggle word wrap

Example: Receiving from a topic created on demand

  ReceiverOptions receiverOptions = new ReceiverOptions();
  receiverOptions.sourceOptions().capabilities("topic");
  Receiver receiver = connection.openReceiver(address, receiverOptions);
Copy to Clipboard Toggle word wrap

7.2. Creating durable subscriptions

A durable subscription is a piece of state on the remote server representing a message receiver. Ordinarily, message receivers are discarded when a client closes. However, because durable subscriptions are persistent, clients can detach from them and then re-attach later. Any messages received while detached are available when the client re-attaches.

Durable subscriptions are uniquely identified by combining the client container ID and receiver name to form a subscription ID. These must have stable values so that the subscription can be recovered.

To create a durable subscription, follow these steps:

  1. Set the connection container ID to a stable value, such as client-1:

      ClientOptions clientOptions = new ClientOptions();
      clientOptions.id("client-1");
      Client client = Client.Create(clientOptions);
    Copy to Clipboard Toggle word wrap
  2. Configure the receiver to act like a topic subscription.

      ReceiverOptions receiverOptions = new ReceiverOptions();
      receiverOptions.sourceOptions().capabilities("topic");
      receiverOptions.sourceOptions().durabilityMode(DurabilityMode.UNSETTLED_STATE);
      receiverOptions.sourceOptions().expiryPolicy(ExpiryPolicy.NEVER);
      Receiver receiver = connection.openDurableReceiver(address, "sub-1", receiverOptions);
    Copy to Clipboard Toggle word wrap

To detach from a subscription, close the receiver.

  1. Delete the subscription.

    receiver.closeAsync();
    Copy to Clipboard Toggle word wrap

if you dont close the receiver then the durable subscription will remain.

7.3. Creating shared subscriptions

A shared subscription is a piece of state on the remote server representing one or more message receivers. Because it is shared, multiple clients can consume from the same stream of messages.

The client configures a shared subscription by setting the shared capability on the receiver source.

Shared subscriptions are uniquely identified by combining the client container ID and receiver name to form a subscription ID. These must have stable values so that multiple client processes can locate the same subscription. If the global capability is set in addition to shared, the receiver name alone is used to identify the subscription.

To create a shared subscription, follow these steps:

  1. Set the connection container ID to a stable value, such as client-1:

      ClientOptions clientOptions = new ClientOptions();
      clientOptions.id("client-1");
      Client client = Client.Create(clientOptions);
    Copy to Clipboard Toggle word wrap
  2. Configure the receiver for sharing by setting the shared capability:

      ReceiverOptions receiverOptions = new ReceiverOptions();
      receiverOptions.sourceOptions().capabilities("topic", "shared");
      receiverOptions.sourceOptions().durabilityMode(DurabilityMode.UNSETTLED_STATE);
      receiverOptions.sourceOptions().expiryPolicy(ExpiryPolicy.NEVER);
      Receiver receiver = connection.openDurableReceiver(address, "sub-1", receiverOptions);
    Copy to Clipboard Toggle word wrap
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat