TCP Socket communication between processes on Heroku worker dyno

十年热恋 提交于 2019-11-29 03:59:53

Use message queue Heroku add-ons ...,

like IronMQ for exsample

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.

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

@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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!