T
- The type of the message payload.public interface Message<T>
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.
Modifier and Type | Method and Description |
---|---|
default CompletionStage<Void> |
ack()
Acknowledge this message.
|
default Message<T> |
addMetadata(Object metadata)
Creates a new instance of
Message with the current metadata, plus the given one. |
default Supplier<CompletionStage<Void>> |
getAck() |
default Metadata |
getMetadata() |
default <M> Optional<M> |
getMetadata(Class<? extends M> clazz)
Retrieves the metadata associated with the given class.
|
default Function<Throwable,CompletionStage<Void>> |
getNack() |
T |
getPayload() |
default CompletionStage<Void> |
nack(Throwable reason)
Acknowledge negatively this message.
|
default CompletionStage<Void> |
nack(Throwable reason,
Metadata metadata)
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,
Iterable<Object> metadata)
Create a message with the given payload and metadata.
|
static <T> Message<T> |
of(T payload,
Iterable<Object> metadata,
Supplier<CompletionStage<Void>> ack)
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,
Metadata metadata)
Create a message with the given payload and metadata.
|
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.
|
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> C |
unwrap(Class<C> unwrapType)
Returns an object of the specified type to allow access to the connector-specific
Message implementation,
and other classes. |
default Message<T> |
withAck(Supplier<CompletionStage<Void>> supplier)
Creates a new instance of
Message with the given acknowledgement supplier. |
default Message<T> |
withMetadata(Iterable<Object> metadata)
Creates a new instance of
Message with the specified metadata. |
default Message<T> |
withMetadata(Metadata metadata)
Creates a new instance of
Message with the specified metadata. |
default Message<T> |
withNack(Function<Throwable,CompletionStage<Void>> nack)
Creates a new instance of
Message with the given negative-acknowledgement function. |
default <P> Message<P> |
withPayload(P payload)
Creates a new instance of
Message with the specified payload. |
static final Logger LOGGER
static <T> Message<T> of(T payload)
T
- The type of payloadpayload
- The payload.static <T> Message<T> of(T payload, Metadata metadata)
T
- The type of payloadpayload
- The payload, must not be null
.metadata
- The metadata, if null
an empty set of metadata is used.static <T> Message<T> of(T payload, Iterable<Object> metadata)
T
- The type of payloadpayload
- The payload, must not be null
metadata
- The metadata, must not be null
, must not contain null
values, can be emptystatic <T> Message<T> of(T payload, Supplier<CompletionStage<Void>> ack)
T
- the type of payloadpayload
- The payload, must not be null
.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.static <T> Message<T> of(T payload, Metadata metadata, Supplier<CompletionStage<Void>> ack)
T
- the type of payloadpayload
- The payload, must not be null
.metadata
- the metadata, if null
, empty metadata are used.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.static <T> Message<T> of(T payload, Iterable<Object> metadata, Supplier<CompletionStage<Void>> ack)
T
- the type of payloadpayload
- The payload.metadata
- the metadata, must not be null
, must not contain null
values.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.@Experimental(value="nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Supplier<CompletionStage<Void>> ack, Function<Throwable,CompletionStage<Void>> nack)
T
- the type of payloadpayload
- The payload.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.nack
- The negative-ack function, this will be invoked when the returned messages nack(Throwable)
method is invoked.@Experimental(value="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)
T
- the type of payloadpayload
- The payload.metadata
- the metadata, must not be null
, must not contain null
values.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.nack
- The negative-ack function, this will be invoked when the returned messages nack(Throwable)
method is invoked.@Experimental(value="nack support is a SmallRye-only feature") static <T> Message<T> of(T payload, Metadata metadata, Supplier<CompletionStage<Void>> ack, Function<Throwable,CompletionStage<Void>> nack)
T
- the type of payloadpayload
- The payload.metadata
- the metadata, must not be null
, must not contain null
values.ack
- The ack function, this will be invoked when the returned messages ack()
method is invoked.nack
- The negative-ack function, this will be invoked when the returned messages nack(Throwable)
method is invoked.default <P> Message<P> withPayload(P payload)
Message
with the specified payload.
The metadata and ack/nack functions are taken from the current Message
.P
- the type of the new payloadpayload
- the new payload.Message
default Message<T> withMetadata(Iterable<Object> metadata)
Message
with the specified metadata.
The payload and ack/nack functions are taken from the current Message
.metadata
- the metadata, must not be null
, must not contains null
.Message
default Message<T> withMetadata(Metadata metadata)
Message
with the specified metadata.
The payload and ack/nack functions are taken from the current Message
.metadata
- the metadata, must not be null
.Message
default Message<T> withAck(Supplier<CompletionStage<Void>> supplier)
Message
with the given acknowledgement supplier.
The payload, metadata and nack function are taken from the current Message
.supplier
- the acknowledgement supplierMessage
@Experimental(value="nack support is a SmallRye-only feature") default Message<T> withNack(Function<Throwable,CompletionStage<Void>> nack)
Message
with the given negative-acknowledgement function.
The payload, metadata and acknowledgment are taken from the current Message
.nack
- the negative-acknowledgement functionMessage
T getPayload()
default Metadata getMetadata()
default <M> Optional<M> getMetadata(Class<? extends M> clazz)
clazz
- the class of the metadata to retrieve, must not be null
Optional
containing the associated metadata, empty if none.default Supplier<CompletionStage<Void>> getAck()
CompletionStage
.@Experimental(value="nack support is a SmallRye-only feature") default Function<Throwable,CompletionStage<Void>> getNack()
default CompletionStage<Void> ack()
@Experimental(value="nack support is a SmallRye-only feature") default CompletionStage<Void> nack(Throwable reason)
nack
is used to indicate that the processing of a message failed. The reason is passed as parameter.reason
- the reason of the nack, must not be null
@Experimental(value="nack support is a SmallRye-only feature; metadata propagation is a SmallRye-specific feature") default CompletionStage<Void> nack(Throwable reason, Metadata metadata)
nack
is 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.reason
- the reason of the nack, must not be null
metadata
- additional nack metadata the connector may use, may be null
default <C> C unwrap(Class<C> unwrapType)
Message
implementation,
and other classes. For example, a Kafka connector could implement this method to allow unwrapping to a specific
Kafka message implementation, or to ConsumerRecord
and ProducerRecord
. If the Message
implementation does not support the target class, an IllegalArgumentException
should be raised.
The default implementation tries to cast the current Message
instance to the target class.
When a connector provides its own Message
implementation, it should override this method to support
specific types.
C
- the target typeunwrapType
- the class of the object to be returned, must not be null
IllegalArgumentException
- if the current Message
instance does not support the calldefault Message<T> addMetadata(Object metadata)
Message
with the current metadata, plus the given one.
The payload and ack/nack functions are taken from the current Message
.metadata
- the metadata, must not be null
.Message
Copyright © 2018–2021 SmallRye. All rights reserved.