How to use zuul to intercept async requests(DeferredResult)? - spring-boot

I am coding a notification system. The clients will get notification from the server by http-long-polling(Spring async requests with DeferredResult). Now I need to limit the total connection the server can hold and the max connection count a client should keep. All connections out of quota will be reject with status code 429 to many reuqests.
I am trying to do this with spring-cloud and zuul. But I have no idea about hou to intecept the lifecycle of an async request with zuul.

Related

In AWS WebSocket API (API Gateway), can I send a message to the client in the $connect route?

When my lambda gets ivoked due to $connect route getting invoked, can I safely send a message to the connection id at this point. Or is the connection not yet fully established? Is it a better idea to use a HTTP response header?
Yes, you should be able to as you will have the client's connectionID. The docs say the connection is established when your integration execution completes.

How to establish a websocket connection from a Twilio webhook?

I am trying to create a chat messaging application, which has text functionality. Right now, when a user sends an SMS message from their phone to a Twilio service number, there is a Twilio webhook which redirects to an endpoint in my backend server: sending HTTP POST request.
However, since it is a chat messaging application, I need the Twilio webhook to establish a Websocket connection (upgrading over HTTP) to my backend server, so that it can send websocket events back to my client.
Is there a way to establish a websocket connection using Twilio webhooks, or even Twilio functions? I can't find any resources online to solve this issue.
I tried Twilio Webhooks, and Twilio Functions, it hasn't worked so far.
WebSockets won't help you in this situation, as the webhook timeout limit is 15 seconds. This means you either need to return a TwiML response within 15 seconds or the request will fail.
It sounds like you want to build a stateful WebSocket connection instead of the stateless API callback. To achieve a stateful session, you either need to handle the state management over multiple incoming messages on your own, or you can use a Studio Flow which comes with state management baked in.

spring zuul route connection reset

I have my API gateway and all my microservices up and running in cloud foundry, and here's my configuration for the API gateway:
zuul.add-proxy-headers=true
zuul.routes.myservice.path=/ptp/myService/**
zuul.routes.myservice.url=${CLIENT_BASE_URL:http://localhost:8877/}/myservice
zuul.routes.myservice.sensitiveHeaders=
zuul.host.connect-timeout-millis=60000
zuul.host.socket-timeout-millis=60000
# Increase the Hystrix timeout to 60s (globally) hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
ribbon.ConnectTimeout=60000
ribbon.ReadTimeout=60000
The problem is that when I try to reach out to my microservice the first time after being idle for some time, I see a connection reset error logged into the API gateway. I don't see anything logged in my client service.
But the same call is successful if I refresh my browser, or if I'm calling the service again.

Reverse pusher - secret needed to receive, not send

Pusher service works as illustrated here:
Does it make sense to use it in reverse direction (and switched data channels)? My use case is as follows:
end users (actually mobile, not browser) send messages to Pusher via HTTP-based REST API
my firewalled machine is connected to Pusher via WebSockets API, subscribes channel and receives messages in realtime
This way I can work with Sandbox plan (only 1 persistent connection is used) but mobile app must contain Puser app key.
From what I understand, anyone can use this key to register subscribe same message stream via websockets. Is there a reverse mode, where receiving messages requires knowing the secret? Maybe other service would suit better?
A more secure solution would be for the mobile clients to use client events. Client events can only be triggered on private channels where the subscription to the channel has to be authenticated.The authentication requests should got to an HTTP endpoint that you control so that you can validate the subscription request.
You firewalled machine can either then have a WebSocket connection and receive the client events over that connection. Or it could receive the client events via client event WebHooks if it exposes an HTTP endpoint.

heroku router timeout/interrupt causing lost responses

I have what appears to be a race condition related to losing responses coming from my heroku web service.
The heroku router delivers the request to the web service, the web service processes the request and returns a response, but in the interim the heroku router fails the request, either due to client (interrupt) or backend timeout.
The problem is that the web service request processing changed state on the backend and expected to send the state change to the client in the body of the response. The response never gets to the client, therefore the state change is lost forever.
The state change in my case happens to be the delivery and removal of a message from a RabbitMQ message queue. The web service request handler pops the request from the RabbitMQ queue, but it fails to reach the client and is never heard of again.
I could implement my own client-based message ACK system to mitigate this. However, I suspect that some of you might have a better solution regarding how to deal with ensuring that the responses get to the client. Is there any callback that I can use on my web service to determine if the response was lost? FWIW my web service is a JAX-RS service running embedded Jetty.
Thanks!

Resources