Interface KafkaRequestReply<Req,Rep>
- Type Parameters:
Req- the type of the request valueRep- the type of the response value
- All Superinterfaces:
io.smallrye.reactive.messaging.EmitterType
- All Known Implementing Classes:
KafkaRequestReplyImpl
@Experimental("Experimental API")
public interface KafkaRequestReply<Req,Rep>
extends io.smallrye.reactive.messaging.EmitterType
KafkaRequestReply is an experimental API that provides functionality for sending requests and receiving
responses over Kafka.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default correlation ID handler identifier.static final StringThe default suffix used to create a separate topic for sending reply messages.static final StringThe default header key used for correlating replies to requests.static final StringThe default header key used for indicating the partition of the reply record.static final StringThe default header key used for indicating the topic of the reply record.static final StringThe config key for the correlation ID handler identifier.static final StringThe config key for specifying the header key used to store the correlation ID in the reply record header.static final StringThe config key for the reply failure handler identifier.static final StringThe config key for specifying the header key used to store the reply partition in the reply record header.static final StringThe config key for the reply partition.static final StringThe config key for the reply timeout.static final StringThe config key for specifying the header key used to store the reply topic in the reply record header.static final StringThe config key for the reply topic. -
Method Summary
Modifier and TypeMethodDescriptionvoidcomplete()Sends the completion event to the channel indicating that no other events will be sent afterward.KafkaConsumer<?,Rep> Retrieves the Kafka Consumer used for consuming messages.Retrieves the pending replies for each topic.static intreplyPartitionFromBytes(byte[] bytes) Calculates the partition header from the given byte array.static byte[]replyPartitionToBytes(int partition) Converts the given partition header integer into a byte array.io.smallrye.mutiny.Uni<org.eclipse.microprofile.reactive.messaging.Message<Rep>>Sends a request and receives a response.io.smallrye.mutiny.Uni<Rep>Sends a request and receives a response.io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>>Blocks until the consumer has been assigned all partitions for consumption.io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>>waitForAssignments(Collection<org.apache.kafka.common.TopicPartition> topicPartitions) Blocks until the consumer has been assigned given partitions for consumption.
-
Field Details
-
DEFAULT_REPLY_CORRELATION_ID_HEADER
The default header key used for correlating replies to requests.- See Also:
-
REPLY_CORRELATION_ID_HEADER_KEY
The config key for specifying the header key used to store the correlation ID in the reply record header.- See Also:
-
DEFAULT_REPLY_TOPIC_HEADER
The default header key used for indicating the topic of the reply record.- See Also:
-
REPLY_TOPIC_HEADER_KEY
The config key for specifying the header key used to store the reply topic in the reply record header.- See Also:
-
DEFAULT_REPLY_PARTITION_HEADER
The default header key used for indicating the partition of the reply record.- See Also:
-
REPLY_PARTITION_HEADER_KEY
The config key for specifying the header key used to store the reply partition in the reply record header.- See Also:
-
DEFAULT_REPLIES_TOPIC_SUFFIX
The default suffix used to create a separate topic for sending reply messages.- See Also:
-
REPLY_TOPIC_KEY
The config key for the reply topic.- See Also:
-
REPLY_PARTITION_KEY
The config key for the reply partition.- See Also:
-
REPLY_TIMEOUT_KEY
The config key for the reply timeout.- See Also:
-
REPLY_CORRELATION_ID_HANDLER_KEY
The config key for the correlation ID handler identifier.This config is used to select a CDI-managed implementation of
CorrelationIdHandleridentified with this config.The correlation ID handler is responsible for generating and handling the correlation ID when replying to a request.
- See Also:
-
DEFAULT_CORRELATION_ID_HANDLER
The default correlation ID handler identifier.The "uuid" correlation ID handler generates unique correlation IDs using universally unique identifiers (UUIDs).
- See Also:
-
REPLY_FAILURE_HANDLER_KEY
The config key for the reply failure handler identifier.This config is used to select a CDI-managed implementation of
ReplyFailureHandlerThe Reply Failure Handler is responsible for extracting failure from the reply record.
- See Also:
-
-
Method Details
-
request
Sends a request and receives a response.- Parameters:
request- the request object to be sent- Returns:
- a Uni object representing the result of the send and receive operation
-
request
io.smallrye.mutiny.Uni<org.eclipse.microprofile.reactive.messaging.Message<Rep>> request(org.eclipse.microprofile.reactive.messaging.Message<Req> request) Sends a request and receives a response.- Parameters:
request- the request object to be sent- Returns:
- a Uni object representing the result of the send and receive operation
-
waitForAssignments
io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> waitForAssignments()Blocks until the consumer has been assigned all partitions for consumption. If areply.partitionis provided, waits only for the assignment of that particular partition. Otherwise, does a lookup for topic partitions and waits for the assignment of all partitions.- Returns:
- a Uni object that resolves to a Set of TopicPartition once the assignments have been made.
-
waitForAssignments
io.smallrye.mutiny.Uni<Set<org.apache.kafka.common.TopicPartition>> waitForAssignments(Collection<org.apache.kafka.common.TopicPartition> topicPartitions) Blocks until the consumer has been assigned given partitions for consumption.- Parameters:
topicPartitions- the number of partitions to wait for assignments- Returns:
- a Uni object that resolves to a Set of TopicPartition once the assignments have been made.
-
getPendingReplies
Map<CorrelationId,PendingReply> getPendingReplies()Retrieves the pending replies for each topic.- Returns:
- a map containing the pending replies for each topic. The map's keys are the topic names and the values are instances of PendingReply.
-
getConsumer
KafkaConsumer<?,Rep> getConsumer()Retrieves the Kafka Consumer used for consuming messages.- Returns:
- the Kafka Consumer used for consuming messages.
-
complete
void complete()Sends the completion event to the channel indicating that no other events will be sent afterward. -
replyPartitionFromBytes
static int replyPartitionFromBytes(byte[] bytes) Calculates the partition header from the given byte array.- Parameters:
bytes- the byte array from which the partition header is calculated- Returns:
- the calculated partition header as an integer
-
replyPartitionToBytes
static byte[] replyPartitionToBytes(int partition) Converts the given partition header integer into a byte array.- Parameters:
partition- the partition header integer to be converted- Returns:
- the byte array representation of the partition header
-