Hi,
I'm facing a strange behavior in a PUB/SUB pattern. I've modified the
psenvpub/psenvsub examples in order to publish different types of messages
so the subscriber can choose.
The publications are of type "A", "B" and "C".
The subscriber subscribes to to publications "A" and "C".
Run the programs and everything goes fine.
Restart the publisher and now the subscriber only gets messages of type "C"
(the "A" subscription was lost?).
If the subscriber subscribes to messages "A", "B" and "C", the situation is
the same, after publisher restart only messages of type "C" are received
(It seems that only the last subscription is kept).
Well, I don't known if it is a mistake in my code or something else. I'm
attaching the codes, but the are pretty the same as in the examples.
BTW, I'm building my examples with ZMQ v4.0.3.
Thanks in advance.
Best regards.
--
Diego Andrés Fons
Intraway Corp.
Solution Developer
AR Office: +54 (11) 6040 4000
US Office: +1 (516) 620 3890
Email: [email protected]
Visit our website at http://www.intraway.com
Proud to be an ISO 9001:2008 certified company
#include <zmq.hpp>
#include <sstream>
#include <iostream>
int main( int argc, char** argv )
{
// Prepare our context and publisher
zmq::context_t context( 1 );
zmq::socket_t publisher( context, ZMQ_PUB );
publisher.bind( "tcp://*:5563" );
char message[ 128 ];
char* keys[] = { "A", "B", "C" };
uint32_t i = 0;
while( true )
{
sprintf( message, "MSG_%d", i );
zmq::message_t frame;
frame.rebuild( strlen( keys[ i%3 ] ) );
memcpy( frame.data(), keys[ i%3 ], strlen( keys[ i%3 ] ) );
bool result = publisher.send( frame, ZMQ_SNDMORE );
frame.rebuild( strlen( message ) );
memcpy( frame.data(), message, strlen( message ) );
result = publisher.send( frame );
std::cout << keys[ i%3 ] << " | " << message << (result ? "" : " !") << std::endl;
sleep( 1 );
i++;
}
return 0;
}
#include <zmq.hpp>
#include <string>
#include <iostream>
int main( int argc, char** argv )
{
// 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, "A", 1 );
subscriber.setsockopt( ZMQ_SUBSCRIBE, "C", 1 );
zmq::message_t frame;
std::string message;
while( true )
{
subscriber.recv( &frame );
message.clear();
message.append( static_cast< char* >( frame.data() ), frame.size() );
if( frame.more() )
{
message.append( " | " );
subscriber.recv( &frame );
message.append( static_cast< char* >( frame.data() ), frame.size() );
}
std::cout << message << std::endl;
}
return 0;
}
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev