-
Notifications
You must be signed in to change notification settings - Fork 60
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
Example is not working #682
Comments
you need to run a NATS Server locally or use the demo server await using var nc = new NatsClient("demo.nats.io"); Also not in the example above you need to create two console apps one for publishing and one for subscribing or place the subscription in a task and don't exist the program. Here is another example that should work out of the box unless outbound TCP port 4222 is blocked by a firewall: // dotnet add package NATS.Net
using NATS.Net;
await using var nc = new NatsClient("demo.nats.io");
var subscription = Task.Run(async () =>
{
await foreach (var msg in nc.SubscribeAsync<string>(subject: "foo"))
{
Console.WriteLine($"Received: {msg.Data}");
if (msg.Data == "exit")
{
break;
}
}
});
for (var i = 0; i < 10; i++)
{
await Task.Delay(1000);
Console.WriteLine("Publishing message...");
await nc.PublishAsync(subject: "foo", data: $"{DateTime.Now} Hello, World!");
}
await nc.PublishAsync(subject: "foo", data: $"exit");
await subscription; |
btw thanks for the heads up @matteoventuri7 we'll add a bit to readme about the server. edit |
Observed behavior
The example reported from Quick Start section inhttps://github.com/nats-io/nats.net is not working.
Error: NATS.Client.Core.NatsException: 'can not connect uris: nats://localhost:4222'
Expected behavior
The example works.
Server and client version
NATS.Net 2.5.4
.Net 8
Host environment
Visual Studio 2022 17.11.6
Windows 11
Steps to reproduce
Create a .Net 8 Console App.
Execute the command dotnet add package NATS.Net
Copy this code:
Run
The text was updated successfully, but these errors were encountered: