Interface Message<T>
- Type Parameters:
T- The type of the message payload.
public interface Message<T>
A message envelope.
Messaging providers may provide their own sub classes of this type, in order to allow messaging provider specific information to be passed to and from applications.
-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletionStage<Void>ack()Acknowledge this message.default Supplier<CompletionStage<Void>>getAck()default Function<Throwable,CompletionStage<Void>> getNack()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>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.default <C> CReturns an object of the specified type to allow access to the connector-specificMessageimplementation, and other classes.withAck(Supplier<CompletionStage<Void>> ack) Creates a new instance ofMessagewith the given acknowledgement supplier.withNack(Function<Throwable, CompletionStage<Void>> nack) 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.
-
Method Details
-
of
Create a message with the given payload.- Type Parameters:
T- The type of payload- Parameters:
payload- The payload.- Returns:
- A message with the given payload, and a no-op ack function.
-
of
Create a message with the given payload and ack function.- 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 and ack function.
-
of
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, ack and nack functions.
-
withPayload
Creates a new instance ofMessagewith the specified payload. The 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
-
withAck
Creates a new instance ofMessagewith the given acknowledgement supplier. The payload, and nack function are taken from the currentMessage.- Parameters:
ack- the positive-acknowledgement function- Returns:
- the new instance of
Message
-
withNack
Creates a new instance ofMessagewith the given negative-acknowledgement function. The payload 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.
-
ack
Acknowledge this message.- Returns:
- a completion stage completed when the message is acknowledged. If the acknowledgement fails, the completion stage propagates the failure.
-
getAck
- Returns:
- the supplier used to retrieve the acknowledgement
CompletionStage.
-
getNack
- Returns:
- the function used to retrieve the negative-acknowledgement asynchronous function.
-
nack
Acknowledge negatively this message.nackis used to indicate that the processing of a message failed with the reason passed as the 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.
-
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 currentMessageinstance 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
-