pomelo icon indicating copy to clipboard operation
pomelo copied to clipboard

How do you make a request from client to backend server when there's multiple backend servers?

Open visgotti opened this issue 7 years ago • 6 comments

So on my client I have the code

  pomelo.request('match_1v1.playerHandler.enterMatch', {},
                function (data) {
                     console.log('entered')
                })

But when it sends that to the server I'm getting an errors

"[2017-03-23 00:02:45.107] [ERROR] pomelo-rpc - [MailStation] [pomelo-rpc] unknown server: [object Object]

[2017-03-23 00:02:45.107] [ERROR] pomelo-rpc - [MailStation] [pomelo-rpc] fail to find remote server:[object Object]

And I know why, it's because I have a routing strategy set up since there's multiple match_1v1 servers


var match1v1Route = function(routeParam, msg, context, cb) {
    var match1v1Servers = app.getServersByType('match_1v1');
    console.log('the routePAram is', routeParam)
    if (! match1v1Servers || match1v1Servers.length === 0) {
        cb (new Error ('can not find 1v1 match servers.'));
        return;
    }
    cb (null, routeParam);
}

app.configure ('production|development', function() {
    app.route('match_1v1', match1v1Route);
})

This works when I'm making rpc calls from a server because I can put the server name in the rpc call as the routeParam, but when I make a call from the client the routeParam is coming up as

the routePAram is FrontendSession {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: 1,
 just FrontendSession object stuff..................

The clients are already in a channel by the time I'm sending the request, so how do I make it so the request uses a routing strategy to go to the correct server?

visgotti avatar Mar 23 '17 04:03 visgotti

When the connector forwards the request to the back-end server it uses the session as the routing param. Try setting some info in the session that you can later use in the routing function.

My advice is to try to keep the back-end servers stateless so it won't matter which instance will serve the request. This way you can scale easier your application by adding or removing back-end instances.

dubanflorin avatar Mar 23 '17 07:03 dubanflorin

I don't think there's a way to structure the game so the match servers can be stateless.. there's too much information the match needs to run the logic for the game the players are in.

How can I set the session information from an rpc call?

because my logic goes connector rpc-> matchmaking rpc-> match

so by the time the matchmaking server puts a player into match, the only data it has is the user's uid, username, and connector server id. Is there a way to get and set a session with that data?

visgotti avatar Mar 23 '17 17:03 visgotti

Maybe the answer is to notify the connector server with the match params and then update the session before making a request to the match server? I will probably try to implement it this way and give an update.

visgotti avatar Mar 23 '17 20:03 visgotti

So that's the logic I went with. Just remember to use session.pushAll() when you update the settings to the session. :)

visgotti avatar Mar 27 '17 23:03 visgotti

hello I'm new here in the pomelo framework and I saw that you got this error ...mailStation) server unknown. I'm starting my server and every time the client tries to connect this message appears with an append at the end ...unknown server: undefined. Could you help me understand this problem?

joaoduavy avatar Sep 03 '22 02:09 joaoduavy

I also wanted to know where this "mailStation" file is called in the base api code.

joaoduavy avatar Sep 03 '22 02:09 joaoduavy