#941·pomelo

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

Author: visgottiCreated Mar 23, 2017Updated Sep 3, 2022

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?