Replies: 6 comments 4 replies
-
Thanks @liukonen this is very helpful. Could you tell us which documentation you were going through? we have the main docs at doc.nats.io and we have the github pages for the client specific docs. |
Beta Was this translation helpful? Give feedback.
-
… On Tue, Feb 4, 2025, 6:45 AM mtmk ***@***.***> wrote:
Thanks @liukonen <https://github.com/liukonen> this is very helpful.
Could you tell us which documentation you were going through? we have the
main docs at doc.nats.io and we have the github pages for the client
specific docs.
—
Reply to this email directly, view it on GitHub
<#735 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGWNTNWFZA2LMV6BIHNKMFL2OCY47AVCNFSM6AAAAABWOO572KVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBVGQ3TKMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
After installing the https://github.com/nats-io/nats.net library in my
dotnet 8 application if you follow the directions listed in the link, none
of the publish or subscribe events occur due to the connection not being
initialized on the using statement. I need to ensure connection is
established using a client. Connectasync before executing publish or
subscribes
…On Tue, Feb 4, 2025, 5:23 PM mtmk ***@***.***> wrote:
I see, thanks for the link. sorry, not sure if I understand correctly. can
you elaborate on the problem you came across? was it confusing which nuget
package to pick?
—
Reply to this email directly, view it on GitHub
<#735 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGWNTNSYAJKP6AKXB2H67VD2OFDXLAVCNFSM6AAAAABWOO572KVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBWGA3TOOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The app I'm putting it in is an asp. Net webapi. I am putting it in its
own. Singlton service where I have it as part of the constructor and on
dispose removing it so its not a timing issue. Also tries just adding it
inline of the api call and tried adding thread sleeps for that potential
issue. I don't have the exact error being returned from the nats code, but
can capture that later if needed
…On Tue, Feb 4, 2025, 11:49 PM mtmk ***@***.***> wrote:
thank you for the details. were you getting a NatsNoRespondersException
after RequestAsync?
(in this example in particular
https://natsbyexample.com/examples/messaging/request-reply/csharp)
thing is with NATS .NET you don't need to explicitly call ConnectAsync.
First call to and other server method e.g. Publish, Subscribe, Request,
will initiate the connection before sending the data to the server.
In the example above, there maybe a race where the subscription task
(defined in this line var responder = Task.Run(async () =>) might start
the subscription *after* the first request is issued, because Task would
be running in the background. Because Connecting before hand would make the
subscription process faster, potentially that was fixing the issue for you.
The solution for that would be to make sure subscription is alive somehow,
or just sleep for a second (for the sake of the example) just before
requests are made.
Let me know if this makes sense and if you can confirm my assumptions
above we can try to fix the example.
—
Reply to this email directly, view it on GitHub
<#735 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGWNTNST5LRPF4BIUQAPSP32OGQ7VAVCNFSM6AAAAABWOO572KVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBWGMYDIOA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Error getting
NATS.Client.Core.NatsNoReplyException: 'No reply received'
Class (loaded as a singleton)
using NATS.Net;
using System;
using System.Threading.Tasks;
using NATS.Client.Core;
using StocksDotNet.Service.Interfaces;
namespace StocksDotNet.Service.Implementations
{
public class NatsService: INatsService, IAsyncDisposable
{
private readonly NatsClient _client;
public NatsService()
{
var password =
Environment.GetEnvironmentVariable("NATS_PASSWORD");
var server = Environment.GetEnvironmentVariable("NATS_SERVER");
var url = "nats://" + Constants.SharedConstants.NATS.USERNAME +
":" + password + "@" + server + ":4222";
_client = new NatsClient(url);
}
public async Task PublishMessageAsync(string subject, string
message)
{
//Invokding the below commented out code makes it work
//if (_client.Connection.ConnectionState !=
NatsConnectionState.Open) await _client.ConnectAsync();
await _client.PublishAsync(subject, message);
}
public async Task SubscribeAsync<T>(string Subject, Action<T>
Function)
{
//if (_client.Connection.ConnectionState !=
NatsConnectionState.Open) await _client.ConnectAsync();
await foreach (var msg in _client.SubscribeAsync<T>(Subject))
{
Function(msg.Data);
}
}
public async Task<NatsMsg<T>> FetchAsync<T>(string Subject, string
Message)
{
//if (_client.Connection.ConnectionState !=
NatsConnectionState.Open) await _client.ConnectAsync();
var valueTask = _client.RequestAsync<string, T>(Subject,
Message);
return await valueTask;
}
public ValueTask DisposeAsync()
{
return _client.DisposeAsync();
}
}
}
Luke Liukonen
…On Wed, Feb 5, 2025 at 9:25 AM mtmk ***@***.***> wrote:
We can have a look at the error if you see any.
(btw NatsClient (or NatsConnection) should also be registered as singleton)
—
Reply to this email directly, view it on GitHub
<#735 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGWNTNS5F6IXPDDIQ7KAAB32OIUM7AVCNFSM6AAAAABWOO572KVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBXGEYDGNI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Just as an FYI, not to confuse since I sent the whole class, my subscriber
is actually in a go server (haven't made it to the point of using the
subscriber here) and my error is happening in the fetchasync method calling
to a running subscriber. But thanks for the heads up
…On Wed, Feb 5, 2025, 10:52 PM mtmk ***@***.***> wrote:
You'd get NatsNoReplyException when your subscription isn't replying. You
need to reply in your subscription e.g.:
async Task SubscribeAsync<T>(string Subject, Func<string?, T> Function){
await foreach (var msg in _client.SubscribeAsync<string>(Subject))
{
var result = Function(msg.Data);
await msg.ReplyAsync<T>(result); // <<=== result is sent as response to RequestAsync() call
}}
—
Reply to this email directly, view it on GitHub
<#735 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGWNTNS5J74J2ZLDEEVQYAT2OLTCRAVCNFSM6AAAAABWOO572KVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBXG4ZTCMI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Used the nats dotnet "Net" client (documentation didn't specify core or net) and spent a few hours trying to troubleshoot the code only to find my connection to the server was never established. Either the walkthrough code should specify that or specify which client to use. Thanks 😃
Beta Was this translation helpful? Give feedback.
All reactions