开发者

Process on Heroku that connects to an external socket

I have my server hosted on Heroku. The data source for my app is an external to my app. The following is the way to fetch the data :

  1. Initialize a process that connects to a socket @ the external-party server.
  2. Save the data that comes through this socket connection.

Now my question is, Is it possible on Heroku to launch such processes, which needs to run constantly for-ever, listening to a soc开发者_如何学Goket on an external server?


A processes in Heroku can only listen to HTTP traffic on port 80. Like andy mentioned, Node.js is your best bet for running a service like this on Heroku.


I think this might be a job for Node.js which you can run on heroku. The logic flow will be to connect to the party server with a node.js app and then when data is received it will trigger a "callback" method. This method can then make a web request back to a Rails server with the data.

For examples of something like this, checkout the pubnub node.js sample app:

https://github.com/pubnub/pubnub-api/tree/master/nodejs


If I understand you correctly you need to launch a background process on heroku that connects to an external server -- this process then saves data from the api locally?

Accessing an external service: That I'm aware of Heroku does not restrict access to external hosts or ports. Indeed, I have an app that connects to my mongodb database on mongohq.

Long running process: This is certainly possible using the new Celadon Cedar stack. The new cedar stack uses a concept called a Procfile, this enables running any script (e.g. ruby, bash, node.js) as a process.

Saving the data: Heroku has a read-only filesystem (excepting /tmp), so you'll need to save the data coming from the API in a database (or somewhere similar).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜