Class PubSub

Class Documentation

class PubSub

Public Types

enum class Mode

Values:

enumerator PUB
enumerator SUB

Public Functions

inline PubSub(zmqpp::context &context, Mode mode)

generic constructor sets up the socket and mode

inline ~PubSub()
inline bool has_message(int timeout_ms = 100)

poll for a waiting message

Parameters:

timeout_ms[in] poll timeout in milliseconds (default 100, 0 = non-blocking)

Returns:

true if at least one message is ready to receive

inline void bind(const std::string &addr, const std::string &topic)

publishers bind to a socket endpoint (not for brokers)

Parameters:
  • addr[in] broker endpoint

  • topic[in] default topic that publisher will use

inline void connect_to_broker(const std::string &addr, const std::string &topic)

publishers will use connect when publishing to a broker

Parameters:
  • addr[in] broker endpoint

  • topic[in] default topic that publisher will use

inline void connect(const std::string &addr)

subscribers connect to publishers

Parameters:

addr[in] publisher’s endpoint

inline void subscribe(const std::string &topic)

subscribe to a topic. can be called more than once

Parameters:

topic[in] topic to subscribe to

inline void unsubscribe(const std::string &topic)

unsubscribe from a topic. can be called more than once

Parameters:

topic[in] topic to unsubscribe from

inline std::pair<std::string, std::string> receive()

receive a message from a publisher

Returns:

topic,payload

inline void publish(const json &message_out, const std::string &topic = "")

publish

Parameters:
  • message[in] reference to JSON message

  • topic[in] publishing topic