Communicate between a Rails app and a Node.js app

前端 未结 5 2129
长情又很酷
长情又很酷 2021-02-13 14:41

This question follows a previous one: Shall I use Node.js Instead of Rails for Real-time WebApps?

The question:

What\'s the best way of communic

5条回答
  •  忘了有多久
    2021-02-13 15:13

    It depends on exactly why you're separating the functionality from one to the other. Rails supports REST based separation without any extra work on your part. It's built based on resources from the ground up. That means it would be very simple for you to use an http.Client (or something like Restler) to query against it. You can certainly do the exact same the other way around, using standard Node.js routing (or something like Express) and an HTTP client for Ruby (such as Typhoeus). Though this method incurs the overhead of using a full HTTP request (not necessarily a problem if on an internal network). If you are looking for a more speedy way of communication, I'd say you could go about it using a persistant socket as Raynos suggests.

    Depending on your need, I would suggest that using two separate systems creates extra code complexity, and it may be best for you to reduce it to one framework/language. I'm all for Service Oriented Design, but Rails is a pretty heavy weight and may slow down your over all response times, even with having Node.js working with it.

提交回复
热议问题