-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Headers on KeyValue storage #237
Comments
@davidmcote This is an architectural issue spanning the server and all clients. I am moving this request to the appropriate repo. |
You are saying that it would benefit - but do not describe exactly what the benefit is. A KV is exactly a 2 part item - key and value. It's not 3 part - KVH. We limit the functionality to match other KVs to keep things simple, understandable and to keep avenues open for replacing the backend later with another. So for headers people usually store a serialized hash/map/struct where one of the keys are the metadata. If you can expand why that is not a suitable choice for you we can consider it better. |
Thanks for the reply! The proposal of this ticket is a backward compatible change to the KeyValue API which would allow applications to opt-in to using Headers. Existing application code would continue to use KV in its current form. An application developer choosing to depend on the new capability would certainly have a harder time migrating to another backend, but whether to limit their use of this feature does seem like it would be their decision to make. In my specific use case, I am using a serialization library to store and load structures as values in a key value store. My structures happen to be polymorphic. While serialization of a polymorphic type is no problem, deserialization generally requires type information as input to map back to a class. My serialization library does not encode type information inline and I have limited control over the serialization library. This motivates supplementing the In lieu of this proposal, I'm constrained to either:
Only the solution with Headers appears to avoid changing the encoding scheme of |
The concern about backends is our ability to move to other backends with out user impacting changes. To my mind choice 2 seems most compatible with a KV store. Or perhaps pre/postpend a type hint to the serialized data without the whole overhead of a wrapping structure and multiple unmarshals. The KV implementation is popular specifically because it removes features and complexity from streams. Really reluctant to feature creap into it being a stream. |
Thank you. I appreciate you taking the time to consider this proposal. |
What motivated this proposal?
Message headers encoded separately from a binary-blob payload are extremely handy capability of core NATS and Jetstream.
The lower level library bindings for Jetstream make headers readily accessible for application use, but the
KeyValue
abstraction does not expose access to message headers.Since KV storage is just another stream, there doesn't appear to be a technical limitation to enabling headers. There simply isn't API bindings for it.
What is the proposed change?
Headers
object.Headers
datamember with accessors. Populate it in the constructor fromMessage.getHeaders()
.Who benefits from this change?
Developers are already using Jetstream to store messages with headers. Some would like to do the same with the KeyValue abstraction.
What alternatives have you evaluated?
One may leverage lower level APIs to store KeyValue entries with headers. This is demonstrated below with the natscli. It unfortunately pierces through the KeyValue abstraction and requires the application developer to string munge stream names and subject patterns to access data in the lower level stream.
Demonstration with natscli:
Create a bucket and store KVs, one with a custom header:
Inspect contents of KV with KV CLI. Headers omitted.
Inspect contents of underlying stream to reveal headers.
The text was updated successfully, but these errors were encountered: