Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a spring boot application where there is a rest controller.
It gets invoked from angular and immediately responds with a message background work started.
The controller has also launched a long running service method decorated with #Asynch which completes after 10 minutes. When it completes the service it causes a websocket push to the front end via a topic expected by the front end.
This causes the front end to know that the background processing is done and it enables a new link that the user can now click.
This is loosely based on https://spring.io/guides/gs/messaging-stomp-websocket/.
Some Questions:
Can this objective also be achieved using reactive programming or CompletableFuture without websocket usage as indicated above?
Does it make sense for a Controller to use completableFuture.get() or .join() and thereby wait for the asynchronous service to finish. Is that also not blocking?
Can reactive streams be used for this. Can we instead return a list of two elements as a stream where first row is the message about "background work started" and second message is "background work done"?
Does this make sense? Is there any such non blocking example ?
Related
This question already has an answer here:
Notify only specific user(s) through WebSockets, when something is modified in the database
(1 answer)
Closed 1 year ago.
so I am looking for making a web app that gets data from the server periodically.
my initial thought was issuing an ajax call inside a loop that asks the server if there is news every 2sec so when there are new things to show the server will send data otherwise will just reply with an empty payload
I am wondering if there is a better approach so the server won't waste sources replying to all those unnecessary ajax calls but instead it will only send data to the targeted client
you can use
<p:poll>
tag if you are working with Primefaces or use WebSockets
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
The server should response as soon as possible, isn't the server process always polling if there are requests?
So, it would like a while loop. But why is not CPU(single core) all consumed if there is no visit?
isn't the server process always polling?
Not if that's a reasonable implementation.
There are many implementations of HTTP servers, and communication servers in general, and polling is not a suitable architecture for any of these.
For example, some servers rely on asynchronous I/O operations using events, callbacks and so on. Other implementations rely on blocking socket APIs while operating in multi threaded modes, and there could be other architectures as well...
isn't the server process always polling if there are requests?
No. It is blocking, in either an accept() call or a select() call. No polling.
I'm working on a desktop application that focuses on listening to Cortana states, but I don't want to intercept a specific question and treat that response.
I want to be able to know exactly when I say "Hey cortana!" and it starts listening, and then I want to know exactly when it stops listening and processes an answer.
Is that possible? Does anyone have an idea on how it could be achieved?
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Have this design problem and trying to find a best way to implement it using JMS.
Web App has single Listener and multiple Producer and multiple WorkerBee. Listener pushes messages from its queue to WorkerBee. All of the messages produced are queued in a Listener. I want to implement a process than can send messages from Listener queue to each WorkerBee using some kind of load balancing process. Only single instance of the message occurs in the Listener queue or in the WorkerBee queue.
Whats the best way to do it? Does JMS sounds like a good choice here? How would I push the message from Listener queue to WorkerBee queue?
Open for suggestion :) And appreciate your response.
Messaging is good choice for such task. I think you should use Apache Camel framework as routing platform for described purposes. It allows to divide business logic from integration level in quite graceful way.
Camel supports plenty of components "out-of-box" including JMS endpoints.
You can delegate to one of your WorkerBee's using Load Balancer pattern.
JMS sounds a good option, since you have multiple instances of WorkerBee, make all WorkerBee listen to a single queue, e.g. to InWorkBeeQueue.
Now you can publish messages from Web App listener to InWorkBeeQueue. Write a simple java JMS producer code to publish messages to this queue. Depending on whichever instance of WorkBee is free, it will read message from InWorkBeeQueue and process it.
If you want to avoid writing new JMS producer code, you can directly map messages from Web app queue to InWorkBeeQueue using Apache Camel routes.
Want to improve this post? Add citations from reputable sources by editing the post. Posts with unsourced content may be edited or deleted.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am trying to understand how Facebook's chat feature receives messages without continuously poling the server.
Firebug shows me a single GET XmlHttpRequest continuously sitting there, waiting for a response from the server. After 5 minutes, this never timed out.
How are they preventing timeout?
An AJAX request can just sit there like that indefinitely, waiting for a response?
Can I do this with JSONRequest? I see this at json.org:
JSONRequest is designed to support
duplex connections. This permits
applications in which the server can
asynchronously initiate transmissions.
This is done by using two simultaneous
requests: one to send and the other to
receive. By using the timeout
parameter, a POST request can be left
pending until the server determines
that it has timely data to send.
Or is there another way to let an AJAX call just sit there, waiting, besides using JSONRequest?
Facebook uses a technique which is now called Comet to push messages from the server to the client instead of having the client poll the server.
There are many ways that this can be implemented, with XMLHttpRequest long polling being just one option. The principle behind this method is that the client sends an ordinary XMLHttpRequest but the server doesn't respond until some event happens (such as another user sending a message), so the client is forced to wait. When the client receives a response (or if the request times out) the client simply creates a new request so that it always has one open request to the server.