Replies: 5 comments 6 replies
-
The client does not have the concept of session, but does have a concept of connection to a server. Once established it does not change unless the connection is manually dropped or the server it is connected to goes out of service. |
Beta Was this translation helpful? Give feedback.
-
Thanks @scottf . Let me give more details on my usecase: I'm talking about actual server the gets the request from nats. We will be having cluster of nats servers and cluster of actual servers for a service. So when client (in my case, some backend X service with multiple servers) make a request to another backend service ( some Y service with multiple servers), lets say with username xyz/xyzsessionkey, request hits one of natsservers and then delegates request to actual Y service server first time randomly right. Next time, if we get another request with same sessionkey(or identifier) in next 10/15mins(for example), i want to land it under same actual Y server from nats-server. Hope its clear. Let me know if you need further information. |
Beta Was this translation helpful? Give feedback.
-
It's not per request. The client makes a connection to a specific random server from the list of servers (bootstrap) you give the connection. You can configure the bootstrap with one or more servers. You can configure it to not be random, meaning it will always try the first server in the list without shuffling the list. |
Beta Was this translation helpful? Give feedback.
-
You could make a general request on a subject like "who-can-handle-foo-requests" and each queue listener would respond with a subject, for instance their unique id in the payload "foo-handler-123-session-42" The responder server would then listen (subscribe) to the subject they told the web-server-789 that they would listen on, maybe some unique guid ""foo-handler-123-session-42". You can then maintain that subject in your session and always publish to that specific subject. Only that server instance will respond since they are the only one listening. So a couple things to consider. If you absolutely have to maintain state at the foo handler, I think this is what you need. But if you don't need to maintain state, just make a request reply and let the faster response be your answer, or get all the responses and pick the one you like. Some examples you can look at are here: and here: |
Beta Was this translation helpful? Give feedback.
-
@scottf Trying to understand what you said. In my case, we are going to have "Q Group" for those cluster of actual service servers, so that only one server will respond to the request. Here is my question:
Also i dont see any API in java library to add dynamically some new endpoint to the service which was bootstrapped already?
|
Beta Was this translation helpful? Give feedback.
-
We started using nats server with java client. We have a usecase where we want to maintain sticky sessions. ie, for a user if first request goes to server1, further requests belong to that user should go to that server only. I'm not finding any examples to do that. Is this supported? Can anyone guide on this
Beta Was this translation helpful? Give feedback.
All reactions