Skip to content

Generic Payloads

Experimental

Generic payloads are an experimental feature and the API is subject to change.

When using reactive messaging, Message flow in your system each message has a payload but can also contain metadata, as explained in Messages, Payload, Metadata. The metadata can hold information, for example in an outgoing channel, additional properties of the outgoing message to be sent to the broker.

It is sometimes preferable to continue using the payload signatures, and also being able to attach metadata. Using GenericPayload allows customizing metadata when handling payloads in SmallRye Reactive Messaging @Incoming and @Outgoing methods. GenericPayload is a wrapper type, like the Message, containing a payload and metadata, without requiring handling acknowledgments manually.

1
2
3
4
5
@Outgoing("out")
Multi<GenericPayload<String>> produce() {
    return Multi.createFrom().range(0, 100)
            .map(i -> GenericPayload.of(">> " + i, Metadata.of(new MyMetadata())));
}

You can combine generic payloads with metadata injection :

1
2
3
4
5
6
7
8
@Incoming("in")
@Outgoing("out")
GenericPayload<String> process(int payload, MyMetadata metadata) {
    // use the injected metadata
    String id = metadata.getId();
    return GenericPayload.of(">> " + payload + " " + id,
            Metadata.of(metadata, new MyMetadata("Bob", "Alice")));
}

Note that the metadata provided with the outgoing generic payload is merged with the incoming message metadata.

Limitations

There are several limitations for the use of GenericPayload: GenericPayload is not supported in emitters, as normal outgoing Message can be used for that purpose. While GenericPayload<T> can be used as an incoming payload type, message converters are not applied to the payload type T.