ServiceStack.Client服务器已发送事件未处理

时间:2018-06-27 13:45:21

标签: c# servicestack

我有一个基本的Hello World控制台程序,该程序连接到Web服务器,但是没有调用我的回调(没有任何内容打印到控制台上)。

using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("start ...");

            try
            {
                // http://docs.servicestack.net/csharp-server-events-client
                // ServiceSack.Client
                var client = new ServerEventsClient("http://localhost:9999/bus/api/v1/subscribe/karli/head/0")
                {
                    OnConnect = connectEvent => Console.WriteLine($"OnMessage {connectEvent}"),
                    OnCommand = cmd => Console.WriteLine($"OnCommand {cmd}"),
                    OnMessage = msg => Console.WriteLine($"OnMessage {msg}"),
                    OnUpdate = upd => Console.WriteLine($"OnUpdate {upd}"),
                    OnException = err => Console.WriteLine($"OnException {err}")
                }.Start();

                // keep main thread running ... 
                var a = Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine("dasda {0}", ex);
            }
        }

        private static void OnMessage(ServerEventMessage message)
        {
            Console.WriteLine($"OnMessage {message}");
        }

    }
}

卷曲正常时

$ curl "http://localhost:9999/bus/api/v1/subscribe/karli/head/0/event-stream"
{"key":"1","offset":0,"value":{}}
{"key":"1","offset":1,"value":{}}
{"key":"1","offset":2,"value":{}}
{"key":"1","offset":3,"value":{}}
{"key":"1","offset":4,"value":{}}
{"key":"1","offset":5,"value":{}}
{"key":"1","offset":6,"value":{}}

我在这里想念什么?

1 个答案:

答案 0 :(得分:1)

ServerEventsClient需要使用ServiceStack服务所在的 BaseUrl 进行初始化。如果您不在自定义路径上托管ServiceStack,那么它将只是主机名,例如:

var client = new ServerEventsClient("http://localhost:9999/") {
///...
}.Start();