Search code examples
rpcdeepstream.io

How does one correctly set up a server based deepstream RPC provider?


I am building a SOA with deepstream and I want to use a deepstream client server to perform API-KEY based look ups that the user should not know. How do I actually set up an RPC client provider? I have looked in the deepstream docs and on google, but there is not a full code example on how to do this. I have created a file like below and run it with node. The output I get is below it:

var deepstream = require('deepstream.io-client-js')
const client = deepstream('localhost:6020').login()
console.log('Starting up')
client.on('error', (error,event,topic) => {
  console.log(error, event, topic);
})

client.on('connectionStateChanged', connectionState => {
  console.log(connectionState);
})

client.login({username: 'USER', password: 'PASSWORD'}, (success, data) => {
  if (success) {
    client.rpc.provide('the-rpc', function( data, response ){
      response.send(data);
    });
  } else {
    console.log(data);
  }
})

--

Starting up
AWAITING_CONNECTION

As you can see it runs the code, but does not actually connect to the deepstream server. I already have the deepstream server running, and a browser client that connects to it, so the config is correct. Please help!


Solution

  • I think your issue is based on the fact your trying to connect node via the webport. Try using port 6021 instead for tcp ( used by the node client ).

    const client = deepstream('localhost:6021').login()
    

    You should also only call .login() once, so the line would be:

    const client = deepstream('localhost:6021')
    

    We are working on a 2.0 release coming out very soon which will remove tcp entirely and only require a single port to make life easier in terms of deployment and performance.