MyNatsClient.Rx
0.12.0
dotnet add package MyNatsClient.Rx --version 0.12.0
NuGet\Install-Package MyNatsClient.Rx -Version 0.12.0
<PackageReference Include="MyNatsClient.Rx" Version="0.12.0" />
paket add MyNatsClient.Rx --version 0.12.0
#r "nuget: MyNatsClient.Rx, 0.12.0"
// Install MyNatsClient.Rx as a Cake Addin
#addin nuget:?package=MyNatsClient.Rx&version=0.12.0
// Install MyNatsClient.Rx as a Cake Tool
#tool nuget:?package=MyNatsClient.Rx&version=0.12.0
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()));
}));
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6
- MyNatsClient (>= 0.12.0)
- System.Reactive (>= 4.0.0)
-
.NETStandard 2.0
- MyNatsClient (>= 0.12.0)
- System.Reactive (>= 4.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MyNatsClient.Rx:
Package | Downloads |
---|---|
M5x.Nats
Package Description |
|
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 |
---|