简体   繁体   English

CoffeeScript ZMQ Pub不发送消息

[英]CoffeeScript ZMQ Pub not sending Messages

The same pub-sub code works on local machine (Linux zephyr 3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:08:16 UTC 2014 i686 i686 i686 GNU/Linux). 相同的pub-sub代码可在本地计算机上运行(Linux zephyr 3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:08:16 UTC 2014 i686 i686 i686 GNU/Linux).

However, on EC2 machine (Linux <host> 3.2.0-60-virtual #91-Ubuntu SMP Wed Feb 19 04:13:28 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux) it fails. 但是,在EC2计算机(Linux <host> 3.2.0-60-virtual #91-Ubuntu SMP Wed Feb 19 04:13:28 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux)它失败了。 The security group is set to allow all for 19019 port and also, for all TCP ports starting from 0. I tried adding prints in the NodeJS ZMQ module and was able to get the data that I am sending when I added it in flush function. 安全组设置为允许全部用于19019端口,也允许所有从0开始的TCP端口。我尝试在NodeJS ZMQ模块中添加打印,并且在将其添加到flush函数中时能够获取正在发送的数据。 What else could be the problem? 还有什么可能是问题?

I tried listening to pub traffic using tcpflow on port 19019 but it didn't work. 我尝试在端口19019上使用tcpflow侦听酒吧流量,但没有成功。 How can I listen to this traffic? 我该如何收听这些流量?

sudo tcpflow -i eth0 port 19019 and sudo tcpflow -i lo port 19019 sudo tcpflow -i eth0 port 19019 sudo tcpflow -i lo port 19019sudo tcpflow -i lo port 19019

Both didn't work. 两者都不起作用。 Is there any tool through which I can debug this? 有什么工具可以调试吗?

Pub.coffee 酒吧咖啡

zmq = require 'zmq'
dpush_socket = zmq.socket 'pub'
dpush_socket.bind 'tcp://127.0.0.1:19019', (err) ->
  if not err?
    console.log "Bind successful"

dpush_socket.send 'pid' + ' req ' + req.query.pid

Sub.coffee 子咖啡

zmq = require "zmq"

endPoint = "tcp://0.0.0.0:19019"

sub = zmq.socket "sub"
sub.identity = 'worker' + process.pid;
sub.connect endPoint
console.log "worker connected!"

sub.subscribe('')

sub.on "message", (msg) ->
  console.log(sub.identity + 'got ' + msg.toString())

Transport Class shall rather meet each other on the same IP:PORT# 运输等级应在同一IP:PORT#上相遇

Sub .coffee 咖啡

zmq = require "zmq"
#                                    # rather set URL, where PUB .bind() listens
endPoint = "tcp://127.0.0.1:19019"   # endPoint = "tcp://0.0.0.0:19019"

Part of the answer is probably what user3666197 pointed out: you need to bind and connect on the same IP. 答案的一部分可能是user3666197指出的:您需要在同一IP上进行绑定和连接。 I'm not sure what you intend with the 0.0.0.0 address, and it shouldn't work even on your local machine unless you found some undocumented corner of your network stack that supports this behavior. 我不确定使用0.0.0.0地址的目的是什么,并且它甚至在您的本地计算机上也不起作用,除非您发现网络堆栈中某个未记录的角落支持此行为。

The other thing is that you either want to include your send call in your callback, or probably want to use bindSync to ensure that the socket is bound before you attempt to send anything. 另一件事是,您要么想在回调中包括send调用,要么想使用bindSync确保在尝试发送任何内容之前已绑定套接字。 What may be happening is that the socket is discarding your sent message because the socket hasn't completed binding by the time you get to the call. 可能发生的情况是套接字正在丢弃您发送的消息,因为套接字在您到达呼叫时尚未完成绑定。 This could well be different between different machines. 这在不同的机器之间可能会有所不同。

The problem is I use a nodejs cluster module and in each of the work a zmq pub socket is created which binds on same port which messes up the issue. 问题是我使用了一个nodejs集群模块,并且在每个工作中都创建了一个zmq pub套接字,该套接字绑定在同一端口上,这弄乱了问题。 On my local machine its a single worker spawning. 在我的本地计算机上,它产生了一个工人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM