I'm looking to get the native message identifier for a Message
that I received from GCP Pub/Sub through Spring Cloud Stream.
I see that there's an identifier in Message
that Spring Cloud Stream sets:
/**
* The key for the Message ID. This is an automatically generated UUID and
* should never be explicitly set in the header map <b>except</b> in the
* case of Message deserialization where the serialized Message's generated
* UUID is being restored.
*/
public static final String ID = "id";
However, I'm looking for the native message identifier -- the one that GCP Pub/Sub (or another service, for instance) would set. Ideally I'd like to be able to use the same approach irrespective of where my message is going and stay agnostic. Where's the right place to look, if there is one?
CodePudding user response:
I am not sure you can have a completely agnostic solution - kafka has no concept of a native message id, for example.
id
is reserved (by spring-messaging).
It looks like the pub/sub adapter has a header mapper that maps all inbound headers, by default.
If the native header is something other than id
, it will be mapped.
The inbound channel adapter supports using a custom mapper (which could map a native id
to something else), but it doesn't look like the binder currently supports configuring a custom mapper into the adapter.