-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSE Output Wrong #220
Comments
The problem is with event field being empty string. Could you try this: return response.writeAndFlush(new ServerSentEvent(null, "data", JsonUtility.mapToJson(data))); If you look into the spec: http://dev.w3.org/html5/eventsource/#event-stream-interpretation, it seems that event field with no value is also valid.
|
What do you mean by that? I'm basing the "working" off of the fact that the browser is not correctly reading the stream when it has the |
Using return response.writeAndFlush(new ServerSentEvent(null, "data", JsonUtility.mapToJson(data))); that emits something I'd never expect:
And this ... return response.writeAndFlush(new ServerSentEvent(null, "", JsonUtility.mapToJson(data))); emits ..
However, this one seems to emit the right thing: return response.writeAndFlush(new ServerSentEvent(null, null, JsonUtility.mapToJson(data))); Thus I'd argue that we should have an overload on ServerSentEvent that just takes the data. I also suggest that we should be able to just write a string and have it do the right thing instead of allocating a |
API is fine, but we could add check for empty string and not send anything if it is found: public ServerSentEvent(String eventId, String eventType, String eventData) You should provide three values. They will be assigned to id, event and data fields respectively. |
The API is not fine if it takes me talking to the author of the library to use it and get expected results :-) In 2+ years of using SSE I have never once needed Using Chrome, I can not get an EventSource stream to work when var es = new EventSource("http://localhost:7979/hystrix-dashboard/proxy.stream?origin=http%3A%2F%2Flocalhost%3A8888")
es.addEventListener('message', function(e) {
console.log(e.data);
}, false); I am no expert on the spec, I just know that the simple case of emitting "data:" only works when eventId does not exist and I don't know how to use SSE when eventId is there, and our current API forces a decision about it. |
I have created an improvement issue for this (#222). |
Thank you. |
Also, how does the |
As I understand it, event field may contain any value which semantic is defined by the application. W emit it according to the spec. SSE standard is more precise about event id handling. For that I created an improvement issue some time ago: #153, but there was no discussion about when and how to implement it. We could leverage for that rx-netty-contexts. |
Not sure what that means ... can you show me Javascript code that runs in Chrome/Safari that correctly consumes the RxNetty output with eventIDs in it? I can't figure it out. When eventID is included as per the RxNetty implementation no data flows when using this code: var es = new EventSource("http://hostname:port/rxnetty-server")
es.addEventListener('message', function(e) {
console.log(e.data);
}, false); |
I was looking into this, and I can only confirm that there is a problem with handling the SSE event stream generated by RxNetty example in the browser. If you look at the example from Mozilla: https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events, we render the content in the very same way. There is a note in the standard, that chunked encoding causes some problems for SSE stream:
This is more about a delay in stream delivery. I will try to find some existing SSE streams properly handled by the browsers to compare what we do differently. Do you know some? |
Good description of handling of SSE events with custom event types is provided here: https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events. "use strict";
function receiveMessages() {
if (typeof(EventSource) !== "undefined") {
// Yes! Server-sent events support!
var source = new EventSource('/aggregator-api/message/stream');
source.onmessage = function (event) {
console.log(event);
var data = event.data;
var id = event.lastEventId;
var newEntry = '<div class="message"> data only=' + data + '</span></div>';
document.body.innerHTML = newEntry + document.body.innerHTML;
};
source.onopen = function (event) {
// Connection was opened.
console.log('opened')
};
source.onclose = function (event) {
// Connection was closed.
console.log('connection closed')
};
source.addEventListener("ping", function(event) {
console.log(event);
var data = event.data;
var id = event.lastEventId;
var newEntry = '<div class="message"> ping with id=' + id + ',and data=' + data + '</span></div>';
document.body.innerHTML = newEntry + document.body.innerHTML;
},
false
);
} else {
// Sorry! No server-sent events support..
console.log('SSE not supported by browser.')
}
}
window.onload = receiveMessages ; |
ReactiveX#205 (Move SSE related classes to http): This is a new implementation of SSE for some optimizations and spec compliance. ReactiveX#209 (Deprecated all SSE classes in text pkg): SSE is only applicable to HTTP. ReactiveX#220 (SSE Output confusion): Default case only emits data event. ReactiveX#222 (Improved SSE API): Better construction semantics. ReactiveX#30 (Optimized SSE decoder): Rewrite of the existing decoder.
PR #266 reimplements SSE in the package io.reactivex.netty.protocol.http.sse and the following are the primary changes w.r.t this issue:
|
I am trying to create a Turbine server (https://github.com/Netflix/Turbine/tree/2.x) that outputs a stream to the Hystrix dashboard (https://github.com/Netflix/Hystrix/tree/master/hystrix-dashboard). The output when using
ServerSentEvent
does not work.Here is the manually written code that works and then the one using
ServerSentEvent
that doesn't work.It appears related work was done in #141 but the comments in that one suggest it may be the cause of this issue.
Using
ServerSentEvent
it emits like this:what is needed is:
The text was updated successfully, but these errors were encountered: