MyNatsClient.Encodings.Json
0.12.0-pre1
dotnet add package MyNatsClient.Encodings.Json --version 0.12.0-pre1
NuGet\Install-Package MyNatsClient.Encodings.Json -Version 0.12.0-pre1
<PackageReference Include="MyNatsClient.Encodings.Json" Version="0.12.0-pre1" />
paket add MyNatsClient.Encodings.Json --version 0.12.0-pre1
#r "nuget: MyNatsClient.Encodings.Json, 0.12.0-pre1"
// Install MyNatsClient.Encodings.Json as a Cake Addin
#addin nuget:?package=MyNatsClient.Encodings.Json&version=0.12.0-pre1&prerelease
// Install MyNatsClient.Encodings.Json as a Cake Tool
#tool nuget:?package=MyNatsClient.Encodings.Json&version=0.12.0-pre1&prerelease
Pub-Sub sample
Simple pub-sub sample showing one client that publishes and one that subscribes. This can of course be the same client and you can also have more clients subscribing etc.
Publisher
var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);
await client.PubAsync("tick", GetNextTick());
//or using an encoding package e.g. Json
await client.PubAsJsonAsync("tickItem", new Tick { Value = GetNextTick() });
Subscriber
var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);
await client.SubAsync("tick", stream => stream.Subscribe(msg => {
Console.WriteLine($"Clock ticked. Tick is {msg.GetPayloadAsString()}");
}));
//or using an encoding package e.g Json
await client.SubAsync("tickItem", stream => stream.Subscribe(msg => {
Console.WriteLine($"Clock ticked. Tick is {msg.FromJson<TestItem>().Value}");
}))
Stream.Subscribe vs Stream.SubscribeSafe
If you subscribe to e.g. the MessageOpStream
using Stream.Subscribe
and your handler is throwing an exception. That handler will get OnError
invoked and then removed.
await client.SubAsync("mySubject", stream => stream.Subscribe(msg => DoSomething(msg)));
If you instead subscribe using Stream.SubscribeSafe
any unhandled exception will get swallowed.
await client.SubAsync("mySubject", stream => stream.SubscribeSafe(msg => DoSomething(msg)));
Request-Response sample
Simple request-response sample. This sample also makes use of two clients. It can of course be the same client requesting and responding, you can also have more responders forming a queue group. Where one will be giving the answer.
Requester
var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);
var response = await client.RequestAsync("getTemp", "stockholm@sweden");
Console.WriteLine($"Temp in Stockholm is {response.GetPayloadAsString()}");
Responder
var cnInfo = new ConnectionInfo("192.168.1.10");
var client = new NatsClient(cnInfo);
await client.SubAsync("getTemp", stream.Subscribe(msg => {
client.Pub(msg.ReplyTo, getTemp(msg.GetPayloadAsString()));
}));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.1
- MyNatsClient (>= 0.12.0-pre1)
- Newtonsoft.Json (>= 11.0.2)
-
.NETStandard 2.0
- MyNatsClient (>= 0.12.0-pre1)
- Newtonsoft.Json (>= 11.0.2)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on MyNatsClient.Encodings.Json:
Package | Downloads |
---|---|
M5x.Nats
Package Description |
|
Serilog.Sinks.Nats
Serilog sink for NATS messaging server |
|
Mi.Fx.Nats
macula.io Nats abstraction |
|
Mi.Fx.Contract
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|