server-sent-events | WebFlux Server using the Spring WebFlux framework | Pub Sub library
kandi X-RAY | server-sent-events Summary
kandi X-RAY | server-sent-events Summary
WebFlux Server using the Spring WebFlux framework and reactive Kafka which exposes a REST API for the clients to make secure HTTP requests. Once a secure connection is established between the client and the web flux server, it consumes messages from Kafka topics and pushes the data asynchronously without closing connection with the client unless required.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Starts the server
- Generate a number of messages
- Closes the producer
- The Kafka receiver
- Auxiliary method that returns events received from Kafka
- The main entry point
server-sent-events Key Features
server-sent-events Examples and Code Snippets
Community Discussions
Trending Discussions on server-sent-events
QUESTION
I'm trying to use the following example of Server Sent Events. Seems like the server is emitting the data, but the event is not firing and no data is recorded in the event stream (through the developer tools).
Angular code (service):
...ANSWER
Answered 2021-Dec-21 at 09:06I just realized, thanks to this answer, that events must be formatted in a specific way. I changed the value of res.write
accordingly:
QUESTION
I'm currently working with server-sent-events using RESTEasy in Wildfly. So far everything is working, except that sometimes the SSE implementation doesn't somehow recognize that the client(s) listening to events is/are already closed (also the close() method of the SseEventSource
on the client-side was called). In aspect of the program logic this isn't a problem at all.
But unfortunately org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl
class which is used to send the events, does - in addition to reporting the exception back to org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl
- not only report the exception, but also logs it using the failedToWriteSseEvent(String, Throwable)
method of the org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages
(later class is based on the JBoss logging). So I get every now and then an unnecessary log messages on level ERROR telling me that the connection was closed by the client. And it get that entry in the log in addition to the onClose event I get from the SseBroadcaster
.
Configuring the JBoss logging seems impossible as the log name is org.jboss.resteasy.resteasy_jaxrs.i18n
which is also used for logging other errors (Means just configuring the logger in the log4j.xml of the deployment won't work / also turn off other errors).
ANSWER
Answered 2021-Jun-22 at 15:58You might be hitting RESTEASY-1986. You can filter these out with a log filter though. In CLI something like:
QUESTION
I'm new to server sent events
,
I red trough many tutorials and watched many helpful videos and I still don't understand "what to do with the data that keep growing on every user request" ??.
I use NodeJS
so I started here..
How To Use Server-Sent Events in Node.js to Build a Realtime App
this following example was taken from the above link..
...ANSWER
Answered 2021-Jun-21 at 07:35what to do with the data that keep growing on every user request?
Currently the demo stores all facts, and sends them all out as the starter history for a client. As it is a demo they've not gone into the messy details of how to scale it for running forever.
In a real app you are likely to want to add an id (or timestamp) to each fact. Then you could use this with last-event-id
on reconnect, to just get the facts they missed.
You are also likely to want to store the facts in a SQL DB of some kind, and maybe offer a separate web service to access the history. A client would first request as much history as they need, then start the event source request.
By the way, I'd make this history request service a separate web service if you wanted to scale. With event source the limiting factor for scaling is the number of simultaneous connections, whereas for storing history the limit is the disk space.
Another approach would be to only keep the most recent 100 or so facts, and not worry about a full history. You could do this by having addFact()
first do facts = facts.slice(-99)
before doing the push (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice if that syntax is unfamiliar).
QUESTION
I have a list of objects where each object has many properties (key-value pairs).
We will have many occasions where different API calls, or server-sent-events (via websockets) will return data to update some objects in the list. The difficult thing is that each different call will return only the part of the data for each object, not the full data.
The question is about the most efficient way to replace only the bits that have changed - noting that this data is used in a React application, so we need to also consider immutable consequences.
My idea was simply to match the id
in the original data to the new data, then I would have to loop through the incoming data to find the keys, then replace the original data with that key. It seems like there might be a more efficient way to do this.
ANSWER
Answered 2021-May-21 at 14:17You could take an object with the references to the objects with the same id
without iterating the array.
QUESTION
I am trying to go a simple step beyond the nest doc example in implementing @Sse() in a controller but I never used rxjs untill now so Im a bit confused.
The flow is :
- client send a
POST
request with a file payload - server (hopefully) sends back the newly created
project
with a propstatus:UPLOADED
- client subscribe to sse route described below passing as param the
projectId
it just received from server - in the meantime server is
doingSomeStuff
that could take from 10sec to a min. WhendoingSomeStuff
is done, project status is updated in db fromUPLOADED
toPARSED
My need is for the @Sse decorated function to execute at x interval of time a "status-check" and return project.status
(that may or may not have been updated at the time)
My present code :
...ANSWER
Answered 2021-Apr-27 at 13:11This is a two-step process.
We create an observable out of the promise generated by
this.service.findById()
using thefrom
operator in rxjs. We also use themap
operator to set the format of the object we need when someone subscribes to this observable.We want to return this observable every x seconds.
interval(x)
creates an observable that emits a value after everyx
milliseconds. Hence, we use this and thenswitchMap
to theprojId$
whenever the interval emits a value. TheswitchMap
operator switches to the inner observable whenever the outer observable emits a value.
Please note: Since your server may take 10 sec, to min for doing the operation, you should set the intervalValue
accordingly. In the code snippet below, I've set it to 10,000 milli seconds which is 10 seconds.
QUESTION
I'm creating few microservices using nestjs.
For instance I have x, y & z services all interconnected by grpc but I want service x to send updates to a webapp on a particular entity change so I have considered server-sent-events [open to any other better solution].
Following the nestjs documentation, they have a function running at n interval for sse route, seems to be resource exhaustive. Is there a way to actually sent events when there's a update.
Lets say I have another api call in the same service that is triggered by a button click on another webapp, how do I trigger the event to fire only when the button is clicked and not continuously keep sending events. Also if you know any idiomatic way to achieve this which getting hacky would be appreciated, want it to be last resort.
[BONUS Question]I also considered MQTT to send events. But I get a feeling that it isn't possible for a single service to have MQTT and gRPC. I'm skeptical of using MQTT because of its latency and how it will affect internal message passing. If I could limit to external clients it would be great (i.e, x service to use gRPC for internal connections and MQTT for webapp just need one route to be exposed by mqtt). (PS I'm new to microservices so please be comprehensive about your solutions :p)
Thanks in advance for reading till end! ...ANSWER
Answered 2021-Apr-21 at 19:54You can. The important thing is that in NestJS SSE
is implemented with Observables, so as long as you have an observable you can add to, you can use it to send back SSE events. The easiest way to work with this is with Subject
s. I used to have an example of this somewhere, but generally, it would look something like this
QUESTION
I need my backend to push several answers to my client and I need puppeteer to run backend-side. Puppeteer needs some time to work, but has regular intermediate results and should send updates to the client regulary (in total, one request-responses-cycle takes less than 60secs which seems to be the upper limit for GAE).
Underlying GAE Problem:- Websockets do not work with the standard environment.
- Puppeteer does not work with the flex environment.
As a consequence, I re-implemented my code to use server sent events (which is based on http). I expected that to work in standard. It works fine locally. It does not work on production. It will eventually answer the client but only when I close the connection server side and then send everything in one go. It does not regularly update the client. This only happens on GAE, not locally.
What have I tried?I do flush the sse-response, as otherwise the compression nodejs library leads to a similar behaviour
I also set these headers, esp. X-Accel-Buffering, taken from here:
...ANSWER
Answered 2021-Apr-16 at 17:54Your local GAE [standard] environment is not an exact replica or simulation of GAE production. This is especially true if you are using GAE Python2 standard. You should keep that in mind going forward. I know this because I have also experienced this issue with Server Sent Events. This means something that works in dev environment might not work in production so be very careful to first confirm what works and doesn't in GAE documentation.
GAE standard does not support streaming which is essentially what SSEs are. In addition, App Engine standard has a deadline of 1 minute for each request i.e. each call to App Engine as part of your standard app has to return within a minute
I don't believe GAE Flexible have these restrictions so you should try it. See this link which talks about differences between standard and flexible. When I had this issue years ago (trying to do SSE on Python), I ended up switching to Compute Engine and doing PubSub but there were other reasons for going that route instead of trying GAE Flexible
QUESTION
I'm using a JS library to stream server-sent-events on my html page:
...ANSWER
Answered 2021-Jan-26 at 09:28When your script calls source.stream();
, it is doing an XMLHttpRequest.send()
operation, which is async by default.
So, what is happening:
- user clicks, and
post()
is called - SSE object and its event listener is set up
- source.stream() is called, which sends the request to the server.
callback()
(i.e.clip()
) is called- Server sends back a response
- Your
message
event handler is called textArea.value
is set
Luckily the fix is simple: you only want callback()
to be called when a message is received. So move callback() to be at the end of the message
event handler, not at the end of post()
.
It will do this after every message event that is received. If you only wanted it to happen after the first event, you will need to implement some logic to keep track of how many events have been received. (And if there will only be one message event, you should be using an Ajax call, not an SSE/EventSource call.)
UPDATE: Discussion in the comments are starting to get out of scope of your original question (where the answer is, simply put, "it is async, not sync"). But I think it is worth pointing out here that you set up a new SSE object every time the user clicks the button. Each SSE object will have its own dedicated TCP/IP socket and its own listener function. This is (generally) not a good idea: instead create the SSE connection once at the start of your web app.
And, though your SSE
polyfill library allows using POST, the standard SSE does not. If you only want the app to poll the server when the user presses the button, consider switching from using SSE to normal AJAX.
QUESTION
I am implementing a web interface using React and Flask. One component of this interface is a server sent event that is used to update data in the front end whenever it is updated in a database. This data is quite large and one event could contain over 16000 characters.
The React front end uses a reverse proxy to the flask back end in order to forward API requests to it. When accessing this back end directly, this works fine with the SSEs and the data is pushed as expected. However, when using Nginx to serve the reverse proxy, something weird happens. It seems like nginx buffers and chunks the event stream and does not send the results until it has filled around 16000 characters. If the data from the event is smaller than this, it means the front end will have to wait until more events are sent. If the data from the event is larger, it means the new-lines that tell the EventSource that a message has been received aren't part of the event. This results in the front end receiving event X when event X+1 is sent (that is, when the new-lines actually appear in the stream).
This is the response header when using nginx:
...ANSWER
Answered 2020-Nov-23 at 13:49The above mentioned configuration actually did work. However, the server I was using contained another nginx configuration that was overriding my configuration. When the configuration parameters specific for SSEs were added to that configuration as well, things started working as expected. So this question was correct all along.
QUESTION
I'm quite new to web development and server-sent-events in particular so probably I'm missing something obvious. I'm trying to display a logger on a React page with server-sent-events, which works fine, but I cannot close the eventSource. The server continuously receives requests after eventSource.close() was called.
...ANSWER
Answered 2020-Oct-05 at 07:20Finally, I found a workaround (I still don't understand why the initial approach did not work, though). Instead of using a hook to store the eventListener, I handled everything in the useEffect hook that is called on mount using addEventListener():
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install server-sent-events
You can use server-sent-events like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the server-sent-events component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page