Is there a way of getting access to the fastify request queue in NodeJS? And also knowing when each request in the queue has been disconnected from the sender?
Thanks in advance!
Related
I have set up a express server with 2 endpoints. One of these endpoints never closes the http connection as it uses the http header 'transfer-encoding: chunked' and I am constantly using '''res.write''' to send data through this endpoint every few seconds.
On the client side however when I attempt to make a fetch request from this endpoint, the response doesn't show as it is waiting for the request to finish.
Would it be possible to actually receiving this changing data on the client side, instead of it waiting to complete the request?
Any help is greatly appreciated
I have a Jquery mobile client the sends an Ajax request to the Express server. From the Express server, it connects to the MongoDB using async function. the problem I face is the when the request is sent to MongoDB the responses delays few seconds. before receiving an empty JSON response sent to the client. how to handle the client-side request to wait until the response is received.
Any advice appreciated.
Thank you
I have a controller in Nestjs that handles an HTTP request. There is an IoT device that communicates with the server and sends the latest changes to the server with a post request. At the same time, there is a mobile application that should receive the update in realtime with Websockets.
I know that the HTTP request and Websockets are different concepts in Nestjs, but is there any way to emit an event whenever I receive the HTTP request?
Any idea would be highly appreciated.
There is indeed a proper solution for this. You need an Injectable that contains an RxJS Subject. Whenever your Controller receives a value via the POST request, it delegates the value to the injected service. The service then "instructs" the Subject to emit the value.
On the other side of the chain, inside your WebSocket Gateway #SubscribeMessage, you return an RxJS Observable - which is derived from the Subject - to the connected clients.
More on Subject and Asynchronous responses
Here is the implementation.
I have 2 servers running 24/7 in a single process (file server.js):
TCP Socket Server (from NodeJS's net module)
ExpressJS HTTP Server
My TCP Socket Server receives messages from multiple gps trackers and inserts them on the DB (MySQL). It does that by instantiating a worker (a child process created by .fork() --> file worker.js) whenever it receives a socket connection; the worker will then take care of every following message coming by that socket.
My HTTP Server receives HTTP/AJAX requests from browser clients and answers them. Some of these requests require that my http server send the request to a worker so it can handle it better. The worker will then, later on, send back some information to the server.
Now, here it lies my problem. How can I send the response to the initial request from the browser? Should I just pass around the (req,res) objects from Express and when it comes back to the server, with the worker's information, I send whatever I want to the browser?
I am using socket.io to send data from my sever to clients. There are situations when a client looses its connection but the server gets to know about this only when the next heartbeat is not recieved from the ckient.
the messages that are sent between the client loosing its network connection to the time when the sever derives this from absense of heartbeats are lost and I am not able resend them when the client rconnects.
I know there I can send a callback in my message which the client will call on successfull delivey of message. however this callback is asynchronous and I Am not aware of any way by which I can getto know that the message delivery failed. Can anyone please help me findhow can I capture a failure to delive a message.
Thanks in advance
According to the documentation, you can configure "max reconnection attempts" for
How many times should Socket.IO attempt to reconnect with the server after a a dropped connection. After this we will emit the reconnect_failed event.