0

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

Sorry for the delay. Check your server log, you should have gotten an error since your subject has spaces. In NATS, subjects cannot have spaces, more information here.

I. Kozlovic
  • 796
  • 3
  • 3