Interface Message<T>
- Type Parameters:
T- The type of the message payload.
- All Known Subinterfaces:
TargetedMessages
- All Known Implementing Classes:
TargetedMessages.Default
public interface Message<T>
A message envelope.
A message contains a non-null payload, an acknowledgement function and a set of metadata.
Metadata are indexed using the class name of the values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Function<Metadata,CompletionStage<Void>> static final BiFunction<Throwable,Metadata, CompletionStage<Void>> static final Logger -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletionStage<Void>ack()Acknowledge this message.default CompletionStage<Void>Acknowledge this message.addMetadata(Object metadata) Creates a new instance ofMessagewith the current metadata, plus the given one.default Supplier<CompletionStage<Void>>getAck()default Function<Metadata,CompletionStage<Void>> default Metadatadefault <M> Optional<M>getMetadata(Class<? extends M> clazz) Retrieves the metadata associated with the given class.default Function<Throwable,CompletionStage<Void>> getNack()default BiFunction<Throwable,Metadata, CompletionStage<Void>> default CompletionStage<Void>Acknowledge negatively this message.default CompletionStage<Void>Acknowledge negatively this message.static <T> Message<T>of(T payload) Create a message with the given payload.static <T> Message<T>Create a message with the given payload and metadata.static <T> Message<T>Create a message with the given payload, metadata and ack function.static <T> Message<T>of(T payload, Iterable<Object> metadata, Function<Metadata, CompletionStage<Void>> ackM, BiFunction<Throwable, Metadata, CompletionStage<Void>> nackM) Create a message with the given payload, metadata and ack and nack functions.static <T> Message<T>Create a message with the given payload, metadata and ack function.static <T> Message<T>of(T payload, Iterable<Object> metadata, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, metadata and ack and nack functions.static <T> Message<T>of(T payload, Function<Metadata, CompletionStage<Void>> ackM) Create a message with the given payload and ack function.static <T> Message<T>of(T payload, Function<Metadata, CompletionStage<Void>> ack, BiFunction<Throwable, Metadata, CompletionStage<Void>> nack) static <T> Message<T>of(T payload, Supplier<CompletionStage<Void>> ack) Create a message with the given payload and ack function.static <T> Message<T>of(T payload, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, ack and nack functions.static <T> Message<T>Create a message with the given payload and metadata.static <T> Message<T>of(T payload, Metadata metadata, Function<Metadata, CompletionStage<Void>> ackM, BiFunction<Throwable, Metadata, CompletionStage<Void>> nackM) Create a message with the given payload, metadata and ack and nack functions.static <T> Message<T>of(T payload, Metadata metadata, Supplier<CompletionStage<Void>> ack) Create a message with the given payload, metadata and ack function.static <T> Message<T>of(T payload, Metadata metadata, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, metadata and ack and nack functions.default <R> Message<R>Apply the given modifier function to the current message returning the result for further compositiondefault <C> CReturns an object of the specified type to allow access to the connector-specificMessageimplementation, and other classes.withAck(Supplier<CompletionStage<Void>> supplier) Creates a new instance ofMessagewith the given acknowledgement supplier.withAckWithMetadata(Function<Metadata, CompletionStage<Void>> supplier) Creates a new instance ofMessagewith the given acknowledgement supplier.withMetadata(Iterable<Object> metadata) Creates a new instance ofMessagewith the specified metadata.withMetadata(Metadata metadata) Creates a new instance ofMessagewith the specified metadata.withNack(Function<Throwable, CompletionStage<Void>> nack) Creates a new instance ofMessagewith the given negative-acknowledgement function.Creates a new instance ofMessagewith the given negative-acknowledgement function.default <P> Message<P>withPayload(P payload) Creates a new instance ofMessagewith the specified payload.
-
Field Details
-
LOGGER
-
EMPTY_ACK
-
EMPTY_NACK
-
-
Method Details
-
of
Create a message with the given payload. No metadata are associated with the message, the acknowledgement and negative acknowledgement are immediate.- Type Parameters:
T- The type of payload- Parameters:
payload- The payload.- Returns:
- A message with the given payload, no metadata, and no-op ack and nack functions.
-
of
Create a message with the given payload and metadata. The acknowledgement and negative-acknowledgement are immediate.- Type Parameters:
T- The type of payload- Parameters:
payload- The payload.metadata- The metadata, ifnullan empty set of metadata is used.- Returns:
- A message with the given payload, metadata and no-op ack and nack functions.
-
of
Create a message with the given payload and metadata. The acknowledgement and negative-acknowledgement are immediate.- Type Parameters:
T- The type of payload- Parameters:
payload- The payload.metadata- The metadata, must not benull, must not containnullvalues, can be empty- Returns:
- A message with the given payload, metadata and no-op ack and nack functions.
-
of
Create a message with the given payload and ack function. No metadata are associated with the message. Negative-acknowledgement is immediate.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.- Returns:
- A message with the given payload, no metadata and ack function.
-
of
Create a message with the given payload and ack function. No metadata are associated with the message. Negative-acknowledgement is immediate.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.ackM- The ack function, this will be invoked when the returned messagesack(Metadata)method is invoked.- Returns:
- A message with the given payload, no metadata and ack function.
-
of
Create a message with the given payload, metadata and ack function. Negative-acknowledgement is immediate.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, ifnull, empty metadata are used.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.- Returns:
- A message with the given payload and ack function.
-
of
Create a message with the given payload, metadata and ack function. Negative-acknowledgement is immediate.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.- Returns:
- A message with the given payload and ack function.
-
of
static <T> Message<T> of(T payload, Iterable<Object> metadata, Function<Metadata, CompletionStage<Void>> ackM) Create a message with the given payload, metadata and ack function. Negative-acknowledgement is immediate.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ackM- The ack function, this will be invoked when the returned messagesack(Metadata)method is invoked.- Returns:
- A message with the given payload and ack function.
-
of
@Experimental("nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, ack and nack functions.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.nack- The negative-ack function, this will be invoked when the returned messagesnack(Throwable)method is invoked.- Returns:
- A message with the given payload, metadata, ack and nack functions.
-
of
@Experimental("nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Function<Metadata, CompletionStage<Void>> ack, BiFunction<Throwable, Metadata, CompletionStage<Void>> nack) -
of
@Experimental("nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Iterable<Object> metadata, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, metadata and ack and nack functions.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.nack- The negative-ack function, this will be invoked when the returned messagesnack(Throwable)method is invoked.- Returns:
- A message with the given payload, metadata, ack and nack functions.
-
of
@Experimental("nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Iterable<Object> metadata, Function<Metadata, CompletionStage<Void>> ackM, BiFunction<Throwable, Metadata, CompletionStage<Void>> nackM) Create a message with the given payload, metadata and ack and nack functions.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ackM- The ack function, this will be invoked when the returned messagesack(Metadata)method is invoked.nackM- The negative-ack function, this will be invoked when the returned messagesnack(Throwable, Metadata)method is invoked.- Returns:
- A message with the given payload, metadata, ack and nack functions.
-
of
@Experimental("metadata propagation is a SmallRye-specific feature") static <T> Message<T> of(T payload, Metadata metadata, Supplier<CompletionStage<Void>> ack, Function<Throwable, CompletionStage<Void>> nack) Create a message with the given payload, metadata and ack and nack functions.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ack- The ack function, this will be invoked when the returned messagesack()method is invoked.nack- The negative-ack function, this will be invoked when the returned messagesnack(Throwable)method is invoked.- Returns:
- A message with the given payload, metadata, ack and nack functions.
-
of
@Experimental("metadata propagation is a SmallRye-specific feature") static <T> Message<T> of(T payload, Metadata metadata, Function<Metadata, CompletionStage<Void>> ackM, BiFunction<Throwable, Metadata, CompletionStage<Void>> nackM) Create a message with the given payload, metadata and ack and nack functions.- Type Parameters:
T- the type of payload- Parameters:
payload- The payload.metadata- the metadata, must not benull, must not containnullvalues.ackM- The ack function, this will be invoked when the returned messagesack()method is invoked.nackM- The negative-ack function, this will be invoked when the returned messagesnack(Throwable)method is invoked.- Returns:
- A message with the given payload, metadata, ack and nack functions.
-
withPayload
Creates a new instance ofMessagewith the specified payload. The metadata and ack/nack functions are taken from the currentMessage.- Type Parameters:
P- the type of the new payload- Parameters:
payload- the new payload.- Returns:
- the new instance of
Message
-
withMetadata
Creates a new instance ofMessagewith the specified metadata. The payload and ack/nack functions are taken from the currentMessage.- Parameters:
metadata- the metadata, must not benull, must not containnull.- Returns:
- the new instance of
Message
-
withMetadata
Creates a new instance ofMessagewith the specified metadata. The payload and ack/nack functions are taken from the currentMessage.- Parameters:
metadata- the metadata, must not benull.- Returns:
- the new instance of
Message
-
withAck
Creates a new instance ofMessagewith the given acknowledgement supplier. The payload, metadata and nack function are taken from the currentMessage.- Parameters:
supplier- the acknowledgement supplier- Returns:
- the new instance of
Message
-
withAckWithMetadata
@Experimental("metadata propagation is a SmallRye-specific feature") default Message<T> withAckWithMetadata(Function<Metadata, CompletionStage<Void>> supplier) Creates a new instance ofMessagewith the given acknowledgement supplier. The payload, metadata and nack function are taken from the currentMessage.- Parameters:
supplier- the acknowledgement supplier- Returns:
- the new instance of
Message
-
withNack
@Experimental("metadata propagation is a SmallRye-specific feature") default Message<T> withNack(Function<Throwable, CompletionStage<Void>> nack) Creates a new instance ofMessagewith the given negative-acknowledgement function. The payload, metadata and acknowledgment are taken from the currentMessage.- Parameters:
nack- the negative-acknowledgement function- Returns:
- the new instance of
Message
-
withNackWithMetadata
@Experimental("metadata propagation is a SmallRye-specific feature") default Message<T> withNackWithMetadata(BiFunction<Throwable, Metadata, CompletionStage<Void>> nack) Creates a new instance ofMessagewith the given negative-acknowledgement function. The payload, metadata and acknowledgment are taken from the currentMessage.- Parameters:
nack- the negative-acknowledgement function- Returns:
- the new instance of
Message
-
getPayload
T getPayload()- Returns:
- The payload for this message.
-
getMetadata
- Returns:
- The set of metadata attached to this message, potentially empty.
-
getMetadata
Retrieves the metadata associated with the given class.- Parameters:
clazz- the class of the metadata to retrieve, must not benull- Returns:
- an
Optionalcontaining the associated metadata, empty if none.
-
getAck
- Returns:
- the supplier used to retrieve the acknowledgement
CompletionStage.
-
getAckWithMetadata
@Experimental("metadata propagation is a SmallRye-specific feature") default Function<Metadata,CompletionStage<Void>> getAckWithMetadata()- Returns:
- the supplier used to retrieve the acknowledgement
CompletionStage.
-
getNack
- Returns:
- the function used to retrieve the negative-acknowledgement asynchronous function.
-
getNackWithMetadata
@Experimental("metadata propagation is a SmallRye-specific feature") default BiFunction<Throwable,Metadata, getNackWithMetadata()CompletionStage<Void>> - Returns:
- the function used to retrieve the negative-acknowledgement asynchronous function.
-
ack
Acknowledge this message.- Returns:
- a completion stage completed when the message is acknowledged. If the acknowledgement fails, the completion stage propagates the failure.
-
ack
@Experimental("metadata propagation is a SmallRye-specific feature") default CompletionStage<Void> ack(Metadata metadata) Acknowledge this message.- Returns:
- a completion stage completed when the message is acknowledged. If the acknowledgement fails, the completion stage propagates the failure.
-
nack
Acknowledge negatively this message.nackis used to indicate that the processing of a message failed. The reason is passed as parameter.- Parameters:
reason- the reason of the nack, must not benull- Returns:
- a completion stage completed when the message is negative-acknowledgement has completed. If the negative acknowledgement fails, the completion stage propagates the failure.
-
nack
@Experimental("nack support is a SmallRye-only feature; metadata propagation is a SmallRye-specific feature") default CompletionStage<Void> nack(Throwable reason, Metadata metadata) Acknowledge negatively this message.nackis used to indicate that the processing of a message failed. The reason is passed as parameter. Additional metadata may be provided that the connector can use when nacking the message. The interpretation of metadata is connector-specific.- Parameters:
reason- the reason of the nack, must not benullmetadata- additional nack metadata the connector may use, may benull- Returns:
- a completion stage completed when the message is negative-acknowledgement has completed. If the negative acknowledgement fails, the completion stage propagates the failure.
-
unwrap
Returns an object of the specified type to allow access to the connector-specificMessageimplementation, and other classes. For example, a Kafka connector could implement this method to allow unwrapping to a specific Kafka message implementation, or toConsumerRecordandProducerRecord. If theMessageimplementation does not support the target class, anIllegalArgumentExceptionshould be raised.The default implementation tries to cast the current
Messageinstance to the target class. When a connector provides its ownMessageimplementation, it should override this method to support specific types.- Type Parameters:
C- the target type- Parameters:
unwrapType- the class of the object to be returned, must not benull- Returns:
- an instance of the specified class
- Throws:
IllegalArgumentException- if the currentMessageinstance does not support the call
-
addMetadata
Creates a new instance ofMessagewith the current metadata, plus the given one. The payload and ack/nack functions are taken from the currentMessage.- Parameters:
metadata- the metadata, must not benull.- Returns:
- the new instance of
Message
-
thenApply
Apply the given modifier function to the current message returning the result for further composition- Type Parameters:
R- the payload type of the modified message- Parameters:
modifier- the function to modify the current message- Returns:
- the modified message
-