nats.net icon indicating copy to clipboard operation
nats.net copied to clipboard

Creating JetStream context from encoded connection

Open jonaslagoni opened this issue 1 year ago • 4 comments

Feature Request

I might be missing some piece of information or maybe it's possible to do this another way, but I can't find anything in the docs that enable this.

Use Case:

I have custom serializers and deserializers which I would like to use with JetStream.

Proposed Change:

Make it possible to create a JetStream context from IEncodedConnection.

Who Benefits From The Change(s)?

Those who use encoded connections and JetStream.

Alternative Approaches

I would love to know the alternative way I can have custom serializers and deserializers alongside JetStream context

jonaslagoni avatar Jul 03 '22 11:07 jonaslagoni

I need this, too.

Do you have any update or alternative approaches?

tiliev avatar Nov 09 '22 11:11 tiliev

@tiliev I ended up using the regular IConnection interface and created the IJetStream connection, then before publishing messages I just manually called the serialization functionality. Same when receiving any data, I deserialize it manually.

If you manually write the code for this, over time it will of course be quite tedious, in my case I am generating the code so I found it acceptable 🙂

jonaslagoni avatar Nov 09 '22 11:11 jonaslagoni

Since it is open source, you are welcome to offer a PR, in fact we would love that. It's just not that big a priority since you are not prevented from doing the encoding yourself. In the meantime, as already noted you can just serialize before the publish and deserialize when handling the message. Not sure how this is more tedious than setting up the encoded serialize/deserialize handler, since the bulk of the code is the implementation of serialize/deserialize which is reusable, not the calling of the implementation.

scottf avatar Nov 09 '22 16:11 scottf

My teams stopped using IEncodedConnection for a few reasons:

  1. It's an odd duck interface that we likely wouldn't include if we made NATS C# client again.
  2. You can build a much better one yourself that's usable in more instances.

Ultimately, I too don't think it's worth it.

sixlettervariables avatar Nov 09 '22 17:11 sixlettervariables