I am using two .NET Core Web APIs; one for publishing content and another for subscribing that content using a NATS streaming server.
At publisher side
string clientID = "abc-publisher";
string clusterID = "test-cluster";
string subject = "testing Subject1";
string data = "Testing with the API";
byte[] payload = Encoding.UTF8.GetBytes(data);
try
{
var opts = StanOptions.GetDefaultOptions();
//opts.StartWithLastReceived();
opts.NatsURL = StanConsts.DefaultNatsURL;
using (var c = new StanConnectionFactory().CreateConnection(clusterID, clientID,opts))
{
string returnData = c.Publish(subject, payload, (obj, pubArgs) =>
{
string s = pubArgs.GUID;
});
}
}
catch (Exception ex)
{
string msg = ex.Message.ToString();
}
At Subscriber side
using (var c = new StanConnectionFactory().CreateConnection(clusterID, clientID)) {
var opts = StanSubscriptionOptions.GetDefaultOptions();
opts.StartWithLastReceived();
var s = c.Subscribe(subject, (obj, args) =>
{
str = Encoding.UTF8.GetString(args.Message.Data);
});
}
But when I run the projects I am unable to go to the callback method of the subscriber.