问题描述
我在 Stackoverflow 上阅读了很多,但经过一周的思考和研究,我陷入了困境......
I read a lot on Stackoverflow, but after a week of thinking and research, I am running stuck...
所以我真的要问:)
希望我把问题解释正确,如果没有,请说!
Hope I explain the problem correctly, if not, please say!
问题很简单.我需要 2 台服务器...服务器 A - 只需要每 15 分钟填充一次数据库,而服务器 B 则处理来自服务器 A 的数据.
The problem is simpel. I need 2 servers... Server A - that does nothing more then filling a database every 15 minutes, and server B that does stuff with the data from server A.
让服务器 B 对数据进行 http 请求很容易,但我真正想要的是,服务器 B 在更新数据库数据时从服务器 A 获取套接字更新".
Its easy to let server B do a http request for data, but what I really want, is that server B gets a 'socket update' from server A, whenever it has updated the database data.
问题:服务器 B 并不总是在同一个 URL 上......所以数据库服务器不能简单地执行 get/post 请求,因为它并不总是知道它的 URL.
The problem: is that server B is not always on the same URL.... So the database server cannot simply do a get/post request, cause it will not always know its url.
这就是为什么我希望服务器 B 可以启动到数据库服务器的 socket.io 连接.. 保持对服务器 A 的线路开放,以便服务器 A 可以通过已经建立的套接字连接用它的新数据库数据进行响应....
Thats why I hope, that server B can start a socket.io connection to the database server.. Keeping the line open to server A, so that server A can respond with its new database data, over the already established socket connection....
所以基本上......是否有可能在 2 个服务器之间建立一个通用的 socket.io 连接......就像客户端之间的服务器一样???
So basically... Is it possible to have a common socket.io connection between 2 servers.. just like a server between a client does???
真的谢谢!!!
更新:稍微清理一下.
我有一个股票数据库.它每 15 分钟从一个交易 API 获取所有数据.该服务器绝不能停止!它可以,但很烦人,因为数据会不一致...
I have a stock database.. It gets all data, every 15 minutes, from a trading API.This server must never stop! It could, but its annoying, cause data will be inconsistent...
我有另一个脚本,它将一直在开发中.它对来自数据库服务器的数据进行计算.所以它偶尔会有(开发)错误等..这个脚本不应该停止'数据库股票'脚本......所以我想将它们彼此分开运行.这就是为什么我需要有 2 个服务器相互连接..
I have another script, that is going to be on development all the time.. That does calculations over the data from the database server. So it will have (dev) errors etc once in a while.. This script should not halt the 'database ticker' script... So I want to run them separate from each other. Thats why I need to have 2 servers connecting with each other..
我的数据库从一个固定的 url 运行..但是我的开发脚本取决于我现在从哪里开发..
My database is running from a fixed url.. But my development script depends on from where I develop at the moment..
对于我想要达到的目标,也许有更好的解决方案......?
Maybe there is a way better solution for what I'm trying to reach..?
推荐答案
对于服务器到服务器的通信,您可以使用 socket.io 依赖其中之一和 socket.io-client 另一个.
For server to server communication you can use socket.io dependency on one of them and socket.io-client on the other.
这篇关于服务器之间的 websocket 通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!