23 #ifndef PUBSUBNODE20110506H 24 #define PUBSUBNODE20110506H 26 #include <google/protobuf/message.h> 28 #include "goby/common/node_interface.h" 29 #include "goby/common/protobuf/pubsub_node_config.pb.h" 39 : zeromq_service_(*service)
46 void publish(MarshallingScheme marshalling_scheme,
const std::string& identifier,
47 const std::string& body)
51 glog.is(goby::common::logger::WARN) &&
52 glog <<
"Ignoring publish since we have `using_pubsub`=false" << std::endl;
56 zeromq_service_.send(marshalling_scheme, identifier, body, SOCKET_PUBLISH);
59 void subscribe(MarshallingScheme marshalling_scheme,
const std::string& identifier)
63 glog.is(goby::common::logger::WARN) &&
64 glog <<
"Ignoring subscribe since we have `using_pubsub`=false" << std::endl;
68 zeromq_service_.subscribe(marshalling_scheme, identifier, SOCKET_SUBSCRIBE);
75 glog.is(goby::common::logger::WARN) &&
76 glog <<
"Ignoring subscribe since we have `using_pubsub`=false" << std::endl;
80 zeromq_service_.subscribe_all(SOCKET_SUBSCRIBE);
83 bool using_pubsub()
const {
return cfg_.has_publish_socket() && cfg_.has_subscribe_socket(); }
87 SOCKET_SUBSCRIBE = 103998,
88 SOCKET_PUBLISH = 103999
104 glog.is(goby::common::logger::DEBUG1) &&
glog <<
"Using publish / subscribe." 108 pubsub_cfg.add_socket();
109 subscriber_socket->CopyFrom(cfg_.subscribe_socket());
110 subscriber_socket->set_socket_type(
111 goby::common::protobuf::ZeroMQServiceConfig::Socket::SUBSCRIBE);
112 subscriber_socket->set_socket_id(SOCKET_SUBSCRIBE);
114 glog.is(goby::common::logger::DEBUG1) &&
115 glog <<
"Subscriber socket: " << subscriber_socket->DebugString() << std::endl;
118 pubsub_cfg.add_socket();
119 publisher_socket->CopyFrom(cfg_.publish_socket());
120 publisher_socket->set_socket_type(
121 goby::common::protobuf::ZeroMQServiceConfig::Socket::PUBLISH);
122 publisher_socket->set_socket_id(SOCKET_PUBLISH);
124 glog.is(goby::common::logger::DEBUG1) &&
125 glog <<
"Publisher socket: " << publisher_socket->DebugString() << std::endl;
129 glog.is(goby::common::logger::DEBUG1) &&
130 glog <<
"Not using publish / subscribe. Set publish_socket and subscribe_socket to " 131 "enable publish / subscribe." 135 zeromq_service_.merge_cfg(pubsub_cfg);
159 void publish(
const NodeTypeBase& msg,
const std::string& group =
"")
163 glog.is(goby::common::logger::WARN) &&
164 glog <<
"Ignoring publish since we have `using_pubsub`=false" << std::endl;
168 node_.send(msg, SOCKET_PUBLISH, group);
171 void subscribe(
const std::string& identifier)
175 glog.is(goby::common::logger::WARN) &&
176 glog <<
"Ignoring subscribe since we have `using_pubsub`=false" << std::endl;
180 node_.subscribe(identifier, SOCKET_SUBSCRIBE);
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.
void publish(const NodeTypeBase &msg, const std::string &group="")
Publish a message (of any type derived from google::protobuf::Message)