【问题标题】:Unable to subscribe method at Subscriber side in microsystem using nats streaming无法使用 nats 流在微系统的订阅者端订阅方法
【发布时间】:2020-05-12 18:29:33
【问题描述】:

我正在使用两个 .NET Core Web API;一个用于发布内容,另一个用于使用 NATS 流服务器订阅该内容。

在发布者方面

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();
}

在订阅者方面

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);
   });
 }

但是当我运行项目时,我无法转到订阅者的回调方法。

【问题讨论】:

    标签: c# networking asp.net-web-api nats-streaming-server


    【解决方案1】:

    抱歉耽搁了。 检查你的服务器日志,你应该得到一个错误,因为你的主题有空格。在 NATS 中,主题不能有空格,更多信息here.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 2016-08-11
      • 1970-01-01
      相关资源
      最近更新 更多