-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
By following the Sampe code I try to connect a Spring (Java) server using server sent events. The URL works fine using curl but with EventSource4Net the EventReceived handler is never invoked.
using EventSource4Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using slf4net;
using slf4net.Resolvers;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("start ...");
try
{
CancellationTokenSource cts = new CancellationTokenSource();
EventSource es = new EventSource(new Uri("http://localhost:9999/bus/api/v1/subscribe/karli"), 50000);
es.StateChanged += new EventHandler<StateChangedEventArgs>((o, e) => { Console.WriteLine("New state: " + e.State.ToString()); });
es.EventReceived += new EventHandler<ServerSentEventReceivedEventArgs>((o, e) => { Console.WriteLine("--------- Msg received -----------\n" + e.Message.ToString()); });
es.Start(cts.Token);
Console.WriteLine("EventSource started");
var a = Console.Read();
cts.Cancel();
}
catch (Exception ex)
{
Console.WriteLine("dasda {0}", ex);
}
}
private static void OnMessage(ServerEventMessage message)
{
Console.WriteLine($"OnMessage {message}");
}
}
}
prints:
start ...
slf4net: The factory resolver AppConfigFactoryResolver returned null from GetFactory(). The fallback no operation logger factory will be used instead.
Application information:
Application domain: ConsoleApplication1.vshost.exe
Application path: C:\Users\xxx\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\
Machine name: XXX
EventSource started
New state: CONNECTING
New state: OPEN
After that nothing happens while I would expect the "--------- Msg received -----------\n" + e.Message.ToString()); to be printed as events are being sent
$ curl "http://localhost:9999/bus/api/v1/subscribe/karli" -v
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9999 (#0)
> GET /bus/api/v1/subscribe/karli HTTP/1.1
> Host: localhost:9999
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: application/stream+json
< Transfer-Encoding: chunked
< Date: Thu, 28 Jun 2018 05:00:01 GMT
<
{"key":"1","offset":3,"value":{}}
Metadata
Metadata
Assignees
Labels
No labels