danielwertheim

danielwertheim


notes from a passionate developer

Developer that lives by the mantra "code is meant to be shared".

Share


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

JsonEncoding and bugfixes in my NATS client

Daniel WertheimDaniel Wertheim

Five releases so far in January. Some bugs, some changes and then of course new features. Also managed to both remove support for .NET4.5+ and bring it back again. Sorry for that. The last release just added a new NuGet package MyNatsClient.Encodings.Json which introduces JsonEncoding and some helper extension messages for publishing entities as JSON as well as reconstructing them in your handlers. Lets have a quick look.

Install the new package (.NET4.5+ and .NET Core via Standard 1.6):

install-package MyNatsClient.Encodings.Json  

Import the namespace:

using MyNatsClient.Encodings.Json;  

Publish using extension method, e.g.:

await client.PubAsJsonAsync("mySubject", new MyEntity { Value = 42 });  

Consume and reconstruct entity, e.g.:

await client.SubWithHandlerAsync("mySubject", msg => {  
  var myEntity = msg.FromJson<MyEntity>();

  //do something with it...
});

That's it. More encoders are to come. Will probably add the possibility to injected encoding/encoder or to register them and then have it be looked up by convetion. Not sure yet. Feel free to suggest what more there should be in this area.

Cheers,

//Daniel

Developer that lives by the mantra "code is meant to be shared".

Comments