2014-02-26 89 views
0

我是zeromq新手,我修改了zeromq示例以測試pub-sub模式的行爲,訂閱者訂閱了兩個主題「ABC」和「ABD」,一切順利,但是當我重新啓動發佈者時,用戶端只收到「ABD」。爲什麼?在zeromq發佈商重新啓動後訂閱丟失

#include "zhelpers.hpp" 

int main() 
{ 
    // Prepare our context and subscriber 
    zmq::context_t context(1); 
    zmq::socket_t subscriber (context, ZMQ_SUB); 
    subscriber.connect("tcp://localhost:5563"); 
    subscriber.setsockopt(ZMQ_SUBSCRIBE, "ABC", 3); 
    subscriber.setsockopt(ZMQ_SUBSCRIBE, "ABD", 3); 

    while (1) { 

      // Read envelope with address 
      std::string address = s_recv (subscriber); 
      // Read message contents 
      std::string contents = s_recv (subscriber); 

      std::cout << "[" << address << "] " << contents << std::endl; 
    } 
    return 0; 
} 

酒館

#include "zhelpers.hpp" 

int main() 
{ 
    // Prepare our context and publisher 
    zmq::context_t context(1); 
    zmq::socket_t publisher(context, ZMQ_PUB); 
    publisher.bind("tcp://*:5563"); 

    while (1) 
    { 
     // Write two messages, each with an envelope and content 
     s_sendmore (publisher, "ABC"); 
     s_send (publisher, "We don't want to see this"); 
     s_sendmore (publisher, "ABD"); 
     s_send (publisher, "We would like to see this"); 
     sleep (1); 
    } 
    return 0; 
} 

輸出

[ABC] We don't want to see this 
[ABD] We would like to see this 
[ABC] We don't want to see this 
[ABD] We would like to see this 
[ABC] We don't want to see this 
[ABD] We would like to see this 
//kill and restart publisher 
[ABD] We would like to see this 
[ABD] We would like to see this 
[ABD] We would like to see this 
[ABD] We would like to see this 
[ABD] We would like to see this 
+0

您正在使用哪個版本的0MQ?我無法用3.2.3重現您的問題。 –

回答

0

我不知道,如果你解決了這個問題,但我面對這種情況了。這是ZMQ的一個問題,它實際上是在版本4.0.4中解決的(請參閱this thread)。

問候。