NATS Jetstream optimistic concurrency headers
Opened this issue · 2 comments
Hi, folks! Is it possible to access the special NATS headers on send, for example Nats-Expected-Last-Sequence
These headers would allow event sourcing with CloudEvents. The neat thing is that consumers don't need to do anything. It's more like a quality of service between NATS client and the server.
If not currently possible, are there workarounds? Could we find a way to add support without breaking the current API?
If I understand the current nats_jetstream
protocol implementation correctly, it ignores this header during the CE conversion:
sdk-go/protocol/nats_jetstream/v2/message.go
Lines 57 to 97 in e6a74ef
IMHO it can be added without breaking the API similar to what we do in the Kafka protocol bindings.
I'd be happy with a change to enable this, but not sure on the correct approach. I'm not too familiar to how other protocol bindings work, but http just has an exported struct field:
sdk-go/v2/protocol/http/message.go
Lines 37 to 49 in 6408c01
If you did something similar, users can then just do the following:
var msg binding.Message
if msg, ok := msg.(*jetstreamv2.Message); ok {
fmt.Println(msg.Header)
}