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
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.concurrent.CompletionStage<java.lang.Void>
ack()
Acknowledge this message.T
getPayload()
static <T> Message<T>
of(T payload)
Create a message with the given payload.static <T> Message<T>
of(T payload, java.util.function.Supplier<java.util.concurrent.CompletionStage<java.lang.Void>> ack)
Create a message with the given payload and ack function.default <C> C
unwrap(java.lang.Class<C> unwrapType)
Returns an object of the specified type to allow access to the connector-specificMessage
implementation, and other classes.
-
-
-
Method Detail
-
of
static <T> Message<T> of(T payload)
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
static <T> Message<T> of(T payload, java.util.function.Supplier<java.util.concurrent.CompletionStage<java.lang.Void>> ack)
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.
-
getPayload
T getPayload()
- Returns:
- The payload for this message.
-
ack
default java.util.concurrent.CompletionStage<java.lang.Void> ack()
Acknowledge this message.- Returns:
- a completion stage completed when the message is acknowledged. If the acknowledgement fails, the completion stage propagates the failure.
-
unwrap
default <C> C unwrap(java.lang.Class<C> unwrapType)
Returns an object of the specified type to allow access to the connector-specificMessage
implementation, and other classes. For example, a Kafka connector could implement this method to allow unwrapping to a specific Kafka message implementation, or toConsumerRecord
andProducerRecord
. If theMessage
implementation does not support the target class, anIllegalArgumentException
should be raised. The default implementation tries to cast the currentMessage
instance to the target class. When a connector provides its ownMessage
implementation, 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:
java.lang.IllegalArgumentException
- if the currentMessage
instance does not support the call
-
-