This client provides access to Centrifugo's batch functionality, allowing you to send multiple API commands in a single HTTP request. This reduces network round-trip time and can significantly improve performance when executing multiple operations.
Key features:
- Execute multiple commands in one request
- Sequential or parallel command processing
- Individual error handling for each command
- Reduced network latency through batching
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbatch(BatchRequest request) Execute multiple commands in a single batch request.default BatchResponseExecute multiple commands in a single batch request.
-
Method Details
-
batch
Execute multiple commands in a single batch request.Sends multiple API commands in one HTTP request and receives individual responses for each command. Commands are processed sequentially by default, but can be processed in parallel by setting the parallel flag.
Processing modes:
- Sequential (default): Commands processed one by one in order
- Parallel: Commands processed concurrently for better performance
Benefits:
- Reduced network round-trip time
- Lower connection overhead
- Better performance for multiple operations
- Atomic-like operations when sequential
Important notes:
- Each command result must be checked individually for errors
- Parallel processing may provide better latency with Redis engine
- Commands are independent - one failure doesn't stop others
Example - sequential processing:
BatchRequest request = BatchRequest.builder().commands(List.of( Command.builder() .publish(PublishRequest.builder().channel("chat:room1") .data(Map.of("message", "Hello")).build()) .build(), Command.builder() .publish(PublishRequest.builder().channel("chat:room2") .data(Map.of("message", "World")).build()) .build())) .build(); BatchResponse response = client.batch(request); for (Reply reply : response.getReplies()) { if (reply.getError() != null) { System.err.println("Command failed: " + reply.getError().getMessage()); } }Example - parallel processing:
BatchRequest request = BatchRequest.builder().commands(commands).parallel(true) // Enable // parallel // processing .build(); BatchResponse response = client.batch(request);- Parameters:
request- the batch request containing multiple commands and processing options- Returns:
- the batch response containing individual replies for each command
- See Also:
-
batch
Execute multiple commands in a single batch request.Sends multiple API commands in one HTTP request and receives individual responses for each command. Commands are processed sequentially by default, but can be processed in parallel by setting the parallel flag.
Processing modes:
- Sequential (default): Commands processed one by one in order
- Parallel: Commands processed concurrently for better performance
Benefits:
- Reduced network round-trip time
- Lower connection overhead
- Better performance for multiple operations
- Atomic-like operations when sequential
Important notes:
- Each command result must be checked individually for errors
- Parallel processing may provide better latency with Redis engine
- Commands are independent - one failure doesn't stop others
Example - sequential processing:
BatchRequest request = BatchRequest.builder().commands(List.of( Command.builder() .publish(PublishRequest.builder().channel("chat:room1") .data(Map.of("message", "Hello")).build()) .build(), Command.builder() .publish(PublishRequest.builder().channel("chat:room2") .data(Map.of("message", "World")).build()) .build())) .build(); BatchResponse response = client.batch(request); for (Reply reply : response.getReplies()) { if (reply.getError() != null) { System.err.println("Command failed: " + reply.getError().getMessage()); } }Example - parallel processing:
BatchRequest request = BatchRequest.builder().commands(commands).parallel(true) // Enable // parallel // processing .build(); BatchResponse response = client.batch(request);- Parameters:
fn- the function to configure the batch request- Returns:
- the batch response containing individual replies for each command
- See Also:
-