OpenHiva::Node::CreateSubscriber

Description

Creates a subscriber.

Prototype

template <typename M> std::shared_ptr<OpenHiva::Subscriber> OpenHiva::Node::CreateSubscriber(const std::string &topicName, const std::function<void(M)> &callback, const OpenHiva::TopicOptions &topicOptions = TopicOptions())

Parameters

Parameter

Input/Output

Description

topicName

Input

Name of the topic to be subscribed to. The value must be less than 128 bytes.

callback

Input

Callback function used to register Subscriber. M indicates the message type. Generally, the callback function is invoked after a message is received.

topicOptions

Input

Topic attribute configuration. For details, see OpenHiva::TopicOptions.

Returns

The OpenHiva::Subscriber object is returned, which can be used to subscribe to messages.

Usage

An application uses the CreateSubscriber function to subscribe to published data of a specified Topic and create a cache queue of a specified depth for the data. After the data of the Topic is published and OpenHiva receives the data, OpenHiva invokes the callback function in the thread group to which groupName belongs.

Precautions

  • Non-reentrant, synchronous interface.
  • This interface can be invoked only after OpenHiva::Init is executed. It is invoked through OpenHiva::Node.
  • For data of the same Topic, OpenHiva ensures sequential processing. For data of different Topics, OpenHiva does not provide the processing sequence.
  • Topic callback for deterministic scheduling cannot be locked during callback (including other functions invoked during callback).
  • When the Hiva::Node::CreateSubscriber interface is invoked, the groupName member of TopicOptions is set.
  • M indicates the message type, which must be a subclass of HivaMessage.
  • The message types of the same topic registered by CreatePublisher and CreateSubscriber must be the same.
  • The number of Topic cannot exceed 500. The number of CreatePublisher and CreateSubscriber in the entire system cannot exceed 2048.
  • The length of TopicName cannot exceed 128 bytes. The first character must be a letter or slash (/), and the other characters must be letters, digits, slashes (/), and underscores (_).