senecajs / seneca-redis-pubsub-transport

Seneca micro-services message transport over Redis pubsub
MIT License
16 stars 20 forks source link

How to set the http port of microservice(s) when usig redis transport #38

Closed k33g closed 7 years ago

k33g commented 7 years ago

Hi 👋

I use a hosting solution that allows http port only on 8080 and I would like to know how to "force" the http port of a microservice when using redis transport

my service is like that:

const seneca = require('seneca')({
  transport: {
    redis: {
      url: process.env.REDIS_URL
    }
  }
})

function yo(options) {
  this.add({role: "hello", cmd: "yo"}, (message, reply) => {
    reply(null, {answer: ">>>yo!!!"})
  })
}

seneca
  .use(yo)
  .use('seneca-redis-transport')
  .listen()

and I would like to write something like that:

const seneca = require('seneca')({
  transport: {
    redis: {
      url: process.env.REDIS_URL
    },
    http: { port: 8080 }
  }
})

or like this:

seneca
  .use(yo)
  .use('seneca-redis-transport')
  .listen({
    host: '0.0.0.0',
    port: 8080
  })

thank you for your help 😄

k33g commented 7 years ago

If I try something like that with the microservice:

const seneca = require('seneca')({
  transport: {
    redis: {
      url: process.env.REDIS_URL
    },
    web: { type: 'web', host: '0.0.0.0', port: 8080},
    tcp: { type: 'tcp', host: '0.0.0.0', port: 8080}
  }
})

I can call it like that: http://yoservicedemo.cleverapps.io/act?role=hello&cmd=yo and it's ok

but my client try to query http://127.0.0.1:10101

let clientYo = seneca({
  transport: {
    redis: {
      url: process.env.REDIS_URL
    }
  }
}).client()

  clientYo.act({role: "hello", cmd: "yo"}, (err, item) => {
    console.log(item)
  })

I get something like that:

["client","invalid_origin",{"pg":"","type":"web","id":"pg:","role":"transport","hook":"client","plugin$":{"name":"client$"},"fatal$":true,"meta$":{"id":"0v8rlakxn9tq/zkw424g3jjru","tx":"zkw424g3jjru","pattern":"hook:client,role:transport,type:web","action":"(iaboyz0bhpyf)","plugin_name":"transport","plugin_tag":"-","prior":{"chain":[],"entry":true,"depth":0},"start":1484492508558,"sync":true},"tx$":"zkw424g3jjru","port":10101,"host":"0.0.0.0","path":"/act","protocol":"http","timeout":5555,"max_listen_attempts":11,"attempt_delay":222,"serverOptions":{}},{"kind":"res","res":null,"error":{"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":10101,"trace":[{"method":"POST","url":"http://127.0.0.1:10101/act"}],"isBoom":true,"isServer":true,"data":null,"output":{"statusCode":502,"payload":{"statusCode":502,"error":"Bad Gateway","message":"connect ECONNREFUSED 127.0.0.1:10101"},"headers":{}}},"sync":true,"time":{"client_recv":1484492547152}}]
k33g commented 7 years ago

Ouch! I think I found why it's ko