C++ zeromq_pull
Date: 2020-11-03Last modified: 2024-06-09
Table of contents
#include <spdlog/spdlog.h>
#include <future>
#include <iostream>
#include <string>
#include <zmq.hpp>
#include <zmq_addon.hpp>
int main()
{
zmq::context_t ctx;
zmq::socket_t puller( ctx, zmq::socket_type::pull );
puller.bind( "tcp://*:15555" );
for( auto i = 0; i < 5; ++i ) {
// Receive all parts of the message
std::vector<zmq::message_t> recv_msgs;
zmq::recv_result_t result = zmq::recv_multipart( puller, std::back_inserter( recv_msgs ) );
assert( result && "recv failed" );
// filtra somente o A
if( recv_msgs[0].to_string_view() == "A" ) {
std::cout << "Puller: [" << recv_msgs[0].to_string_view() << "] " << recv_msgs[1].to_string_view() << std::endl;
}
}
return 0;
}
Possible output
xxx