TCP Socket communication between processes on Heroku worker dyno

前端 未结 5 2027
难免孤独
难免孤独 2020-12-16 17:32

I\'d like to know how to communicate between processes on a Heroku worker dyno.

We want a Resque worker to read off a queue and send the data to another process runn

相关标签:
5条回答
  • 2020-12-16 18:10

    Have you tried Fifo?

    http://www.gnu.org/software/libc/manual/html_node/FIFO-Special-Files.html#FIFO-Special-Files

    0 讨论(0)
  • 2020-12-16 18:10

    Heroku only lets you listen in a given port ($PORT) per dyno, I think.

    I see two solutions here:

    • Use Redis as a communication middleware, so the worker would write on Redis again and the listener process, instead of listening in a port would be querying redis for new jobs.

    • Get another heroku dyno (or better, a complete different application) and launch there the listening process (on $PORT) and communicate both applications

    0 讨论(0)
  • 2020-12-16 18:12

    Reading your question, you've answered your own question, you cannot connect to localhost 12345.

    This way of setting up your processes is a strange one as your running two processes within one Heroku dyno which removes a lot of the benefits of Heroku, i.e independant process scaling, isolation and clean depenedency declaration and isolation.

    I would strongly recommend running this as two seperate processes that interact via a third party backing service.

    0 讨论(0)
  • 2020-12-16 18:19

    Use message queue Heroku add-ons ...,

    like IronMQ for exsample

    0 讨论(0)
  • 2020-12-16 18:32

    @makdad, is the "3rd party software" written in Ruby? If so, I would run it with a monkey patch which fakes out TCPSocket or whatever class it is using to access the TCP socket. Put the monkey patch in a file of its own, which will only be required by the Ruby process which is running the 3rd party software. The monkey patch could even read data directly from the queue, and make TCPSocket behave as if that data had been received.

    Yes, it's not very elegant, and I'm sure there may be a better way to do it, but when are you trying to get a job done (not spend days doing research), sometimes you just have to bite the bullet and do something which is ugly, but works. Whatever solution you choose, make sure to document it for those who work on the project later.

    0 讨论(0)
提交回复
热议问题