Interface PublicationClient
This client provides access to Centrifugo's core publication functionality, allowing you to send real-time messages to connected clients through channels. It supports both single-channel publishing and multi-channel broadcasting.
Key features:
- Publish JSON or binary data to channels
- Broadcast same data to multiple channels efficiently
- Publication tagging and metadata
- History control and idempotency
- Delta updates and versioning
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbroadcast(BroadcastRequest request) Broadcast data to multiple channels.default BroadcastResponseBroadcast data to multiple channels.publish(PublishRequest request) Publish data into a channel.default PublishResponsePublish data into a channel.
-
Method Details
-
publish
Publish data into a channel.Sends data to all clients currently subscribed to the specified channel. This is the most commonly used operation for real-time messaging.
Features:
- JSON or binary data support
- Optional history storage control
- Publication tags for metadata
- Idempotency keys for retry safety
- Delta updates for efficiency
- Version control for document state
Example:
PublishRequest request = PublishRequest.builder().channel("chat:room1") .data(Map.of("message", "Hello, World!", "user", "alice")) .tags(Map.of("type", "message")).build(); PublishResponse response = client.publish(request);- Parameters:
request- the publish request containing channel, data, and options- Returns:
- the publish response containing publication offset and epoch
- See Also:
-
publish
Publish data into a channel.Sends data to all clients currently subscribed to the specified channel. This is the most commonly used operation for real-time messaging.
Features:
- JSON or binary data support
- Optional history storage control
- Publication tags for metadata
- Idempotency keys for retry safety
- Delta updates for efficiency
- Version control for document state
Example:
PublishRequest request = PublishRequest.builder().channel("chat:room1") .data(Map.of("message", "Hello, World!", "user", "alice")) .tags(Map.of("type", "message")).build(); PublishResponse response = client.publish(request);- Parameters:
fn- the function to configure the publish request- Returns:
- the publish response containing publication offset and epoch
- See Also:
-
broadcast
Broadcast data to multiple channels.Efficiently sends the same data to multiple channels in a single operation. This is more efficient than making multiple individual publish calls when you need to send identical data to several channels.
Use cases:
- Sending notifications to multiple user channels
- Broadcasting system announcements
- Synchronizing data across related channels
- Fan-out messaging patterns
Example:
BroadcastRequest request = BroadcastRequest.builder() .channels(List.of("user:123", "user:456", "user:789")) .data(Map.of("notification", "System maintenance in 5 minutes")).build(); BroadcastResponse response = client.broadcast(request);- Parameters:
request- the broadcast request containing channels list, data, and options- Returns:
- the broadcast response containing individual publish results for each channel
- See Also:
-
broadcast
Broadcast data to multiple channels.Efficiently sends the same data to multiple channels in a single operation. This is more efficient than making multiple individual publish calls when you need to send identical data to several channels.
Use cases:
- Sending notifications to multiple user channels
- Broadcasting system announcements
- Synchronizing data across related channels
- Fan-out messaging patterns
Example:
BroadcastRequest request = BroadcastRequest.builder() .channels(List.of("user:123", "user:456", "user:789")) .data(Map.of("notification", "System maintenance in 5 minutes")).build(); BroadcastResponse response = client.broadcast(request);- Parameters:
fn- the function to configure the broadcast request- Returns:
- the broadcast response containing individual publish results for each channel
- See Also:
-