chuckremes / ffi-rzmq

FFI bindings for ZeroMQ so the library can be used under JRuby and other FFI-compliant ruby runtimes
242 stars 62 forks source link

Losing Messages with Router/Dealer after Dealer crashes #111

Closed ds1982 closed 9 years ago

ds1982 commented 10 years ago

Hello,

i am pretty new to ZMQ and have started to play around with some Router/Dealer Examples.

My Dealer:

require 'rubygems'
require 'ffi-rzmq'

context = ZMQ::Context.new 1

socket = context.socket ZMQ::DEALER
socket.setsockopt ZMQ::IDENTITY, "CL"
socket.connect 'tcp://localhost:5555'
string =""

while true
socket.recv_string string
puts string
end

My Router:

require 'rubygems'
require 'ffi-rzmq'

context = ZMQ::Context.new 1

socket = context.socket ZMQ::ROUTER
socket.bind 'tcp://*:5555'

while true
sleep 1
puts "sending to CL"
socket.send_string "CL", ZMQ::SNDMORE
socket.send_string "This is the workload for CL"
end

I am experiencing the following: It works independendly which application (Router or Dealer) i start first. When Router crashes for some reason (CTRL-C) i can restart it and everything works fine. When the Dealer crashes while Router is working and i restart it the Router sends the Messages without error, but they are not received again by the Dealer.

Whats wrong here and how can i fix it?

Is Router-Dealer the right pattern for my use-case? I have 3-5 applications which need to send messages to one of the other applications depending on some external things. My idea was to bind a router and connect a dealer in every application to the same port. Is this the wrong pattern?

chuckremes commented 10 years ago

Try changing your router to use “tcp://localhost:5555” just like your dealer instead of using the wildcard. Let me know if you get a different result.

Conversely, try changing both to use the wildcard and try it.

On May 19, 2014, at 12:27 PM, ds1982 notifications@github.com wrote:

Hello,

i am pretty new to ZMQ and have started to play around with some Router/Dealer Examples.

My Dealer:

require 'rubygems' require 'ffi-rzmq'

context = ZMQ::Context.new 1

socket = context.socket ZMQ::DEALER socket.setsockopt ZMQ::IDENTITY, "CL" socket.connect 'tcp://localhost:5555' string =""

while true socket.recv_string string puts string end My Router:

require 'rubygems' require 'ffi-rzmq'

context = ZMQ::Context.new 1

socket = context.socket ZMQ::ROUTER socket.bind 'tcp://*:5555'

while true sleep 1 puts "sending to CL" socket.send_string "CL", ZMQ::SNDMORE socket.send_string "This is the workload for CL" end I am experiencing the following: It works independendly which application (Router or Dealer) i start first. When Router crashes for some reason (CTRL-C) i can restart it and everything works fine. When the Dealer crashes while Router is working and i restart it the Router sends the Messages without error, but they are not received again by the Dealer.

Whats wrong here?

— Reply to this email directly or view it on GitHub.

ds1982 commented 10 years ago

With both the Dealer does not receive any message at all!?

chuckremes commented 10 years ago

I don’t understand. With both? With both what? Using wildcard or not using the wildcard?

On May 19, 2014, at 1:45 PM, ds1982 notifications@github.com wrote:

With both the Dealer does not receive any message at all!?

— Reply to this email directly or view it on GitHub.

ds1982 commented 10 years ago

With both solutions you delivered. I switched router AND dealer to use “tcp://localhost:5555” -> dealer does not receive any message I switched router AND dealer to use “tcp://*:5555” -> dealer does not receive any message

Only if i use the combination "wildcard" on the router and "localhost" on the dealer the messages are delivered like i described initially...

chuckremes commented 10 years ago

Very strange. Any chance you can jump into the irc #zeromq on irc.freenode.net? If not, I recommend opening a bug with the zeromq project and including a complete description of the observed behavior. If you can provide a reproduction of the problem in C, that will enable them to more quickly evaluate and fix the bug.

On May 19, 2014, at 1:52 PM, ds1982 notifications@github.com wrote:

With both solutions you delivered. I switched router AND dealer to use “tcp://localhost:5555” -> dealer does not receive any message I switched router AND dealer to use “tcp://*:5555” -> dealer does not receive any message

Only if i use the combination "wildcard" on the router and "localhost" on the dealer the messages are delivered like i described initially...

— Reply to this email directly or view it on GitHub.

chuckremes commented 9 years ago

Not a bug in ffi-rzmq.