pulsar-client-cpp
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
pulsar::Client Class Reference

Public Member Functions

 Client (const std::string &serviceUrl)
 
 Client (const std::string &serviceUrl, const ClientConfiguration &clientConfiguration)
 
Result createProducer (const std::string &topic, Producer &producer)
 
Result createProducer (const std::string &topic, const ProducerConfiguration &conf, Producer &producer)
 
void createProducerAsync (const std::string &topic, CreateProducerCallback callback)
 
void createProducerAsync (const std::string &topic, ProducerConfiguration conf, CreateProducerCallback callback)
 
Result subscribe (const std::string &topic, const std::string &subscriptionName, Consumer &consumer)
 
Result subscribe (const std::string &topic, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
 
void subscribeAsync (const std::string &topic, const std::string &subscriptionName, SubscribeCallback callback)
 
void subscribeAsync (const std::string &topic, const std::string &subscriptionName, const ConsumerConfiguration &conf, SubscribeCallback callback)
 
Result subscribe (const std::vector< std::string > &topics, const std::string &subscriptionName, Consumer &consumer)
 
Result subscribe (const std::vector< std::string > &topics, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
 
void subscribeAsync (const std::vector< std::string > &topics, const std::string &subscriptionName, SubscribeCallback callback)
 
void subscribeAsync (const std::vector< std::string > &topics, const std::string &subscriptionName, const ConsumerConfiguration &conf, SubscribeCallback callback)
 
Result subscribeWithRegex (const std::string &regexPattern, const std::string &subscriptionName, Consumer &consumer)
 
Result subscribeWithRegex (const std::string &regexPattern, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
 
void subscribeWithRegexAsync (const std::string &regexPattern, const std::string &subscriptionName, SubscribeCallback callback)
 
void subscribeWithRegexAsync (const std::string &regexPattern, const std::string &subscriptionName, const ConsumerConfiguration &conf, SubscribeCallback callback)
 
Result createReader (const std::string &topic, const MessageId &startMessageId, const ReaderConfiguration &conf, Reader &reader)
 
void createReaderAsync (const std::string &topic, const MessageId &startMessageId, const ReaderConfiguration &conf, ReaderCallback callback)
 
Result createTableView (const std::string &topic, const TableViewConfiguration &conf, TableView &tableView)
 
void createTableViewAsync (const std::string &topic, const TableViewConfiguration &conf, TableViewCallback callBack)
 
Result getPartitionsForTopic (const std::string &topic, std::vector< std::string > &partitions)
 
void getPartitionsForTopicAsync (const std::string &topic, GetPartitionsCallback callback)
 
Result close ()
 
void closeAsync (CloseCallback callback)
 
void shutdown ()
 
uint64_t getNumberOfProducers ()
 Get the number of alive producers on the current client.
 
uint64_t getNumberOfConsumers ()
 Get the number of alive consumers on the current client.
 
void getSchemaInfoAsync (const std::string &topic, int64_t version, std::function< void(Result, const SchemaInfo &)> callback)
 

Friends

class PulsarFriend
 
class PulsarWrapper
 

Constructor & Destructor Documentation

◆ Client() [1/2]

pulsar::Client::Client ( const std::string &  serviceUrl)

Create a Pulsar client object connecting to the specified cluster address and using the default configuration.

Parameters
serviceUrlthe Pulsar endpoint to use (eg: pulsar://localhost:6650)
Exceptions
std::invalid_argumentif serviceUrl is invalid

◆ Client() [2/2]

pulsar::Client::Client ( const std::string &  serviceUrl,
const ClientConfiguration clientConfiguration 
)

Create a Pulsar client object connecting to the specified cluster address and using the specified configuration.

Parameters
serviceUrlthe Pulsar endpoint to use (eg: http://brokerv2-pdev.messaging.corp.gq1.yahoo.com:4080 for Sandbox access)
clientConfigurationthe client configuration to use
Exceptions
std::invalid_argumentif serviceUrl is invalid

Member Function Documentation

◆ close()

Result pulsar::Client::close ( )
Returns

◆ closeAsync()

void pulsar::Client::closeAsync ( CloseCallback  callback)

Asynchronously close the Pulsar client and release all resources.

All producers, consumers, and readers are orderly closed. The client waits until all pending write requests are persisted.

Parameters
callbackthe callback that is triggered when the Pulsar client is asynchronously closed successfully or not

◆ createProducer() [1/2]

Result pulsar::Client::createProducer ( const std::string &  topic,
const ProducerConfiguration conf,
Producer producer 
)

Create a producer with specified configuration

See also
createProducer(const std::string&, const ProducerConfiguration&, Producer&)
Parameters
topicthe topic where the new producer will publish
confthe producer config to use
producera non-const reference where the new producer will be copied
Returns
ResultOk if the producer has been successfully created
ResultError if there was an error

◆ createProducer() [2/2]

Result pulsar::Client::createProducer ( const std::string &  topic,
Producer producer 
)

Create a producer with default configuration

See also
createProducer(const std::string&, const ProducerConfiguration&, Producer&)
Parameters
topicthe topic where the new producer will publish
producera non-const reference where the new producer will be copied
Returns
ResultOk if the producer has been successfully created
ResultError if there was an error

◆ createProducerAsync() [1/2]

void pulsar::Client::createProducerAsync ( const std::string &  topic,
CreateProducerCallback  callback 
)

Asynchronously create a producer with the default ProducerConfiguration for publishing on a specific topic

Parameters
topicthe name of the topic where to produce
callbackthe callback that is triggered when the producer is created successfully or not
callbackCallback function that is invoked when the operation is completed

◆ createProducerAsync() [2/2]

void pulsar::Client::createProducerAsync ( const std::string &  topic,
ProducerConfiguration  conf,
CreateProducerCallback  callback 
)

Asynchronously create a producer with the customized ProducerConfiguration for publishing on a specific topic

Parameters
topicthe name of the topic where to produce
confthe customized ProducerConfiguration

◆ createReader()

Result pulsar::Client::createReader ( const std::string &  topic,
const MessageId startMessageId,
const ReaderConfiguration conf,
Reader reader 
)

Create a topic reader with given ReaderConfiguration for reading messages from the specified topic.

The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. Reader can only work on non-partitioned topics.

The initial reader positioning is done by specifying a message id. The options are:

  • MessageId.earliest : Start reading from the earliest message available in the topic
  • MessageId.latest : Start reading from the end topic, only getting messages published after the reader was created
  • MessageId : When passing a particular message id, the reader will position itself on that specific position. The first message to be read will be the message next to the specified messageId.
Parameters
topicThe name of the topic where to read
startMessageIdThe message id where the reader will position itself. The first message returned will be the one after the specified startMessageId
confThe ReaderConfiguration object
Returns
The Reader object

◆ createReaderAsync()

void pulsar::Client::createReaderAsync ( const std::string &  topic,
const MessageId startMessageId,
const ReaderConfiguration conf,
ReaderCallback  callback 
)

Asynchronously create a topic reader with the customized ReaderConfiguration for reading messages from the specified topic.

The Reader provides a low-level abstraction that allows for manual positioning in the topic, without using a subscription. The reader can only work on non-partitioned topics.

The initial reader positioning is done by specifying a message ID. The options are as below:

  • MessageId.earliest : start reading from the earliest message available in the topic
  • MessageId.latest : start reading from the latest topic, only getting messages published after the reader was created
  • MessageId : when passing a particular message ID, the reader positions itself on that is the message next to the specified messageId.
Parameters
topicthe name of the topic where to read
startMessageIdthe message ID where the reader positions itself. The first message returned is the one after the specified startMessageId
confthe ReaderConfiguration object
Returns
the Reader object

◆ createTableView()

Result pulsar::Client::createTableView ( const std::string &  topic,
const TableViewConfiguration conf,
TableView tableView 
)

Create a table view with given TableViewConfiguration for specified topic.

The TableView provides a key-value map view of a compacted topic. Messages without keys will be ignored.

Parameters
topicThe name of the topic.
confThe TableViewConfiguration object
tableViewThe TableView object
Returns
Returned when the TableView is successfully linked to the topic and the map is built from a message that already exists

◆ createTableViewAsync()

void pulsar::Client::createTableViewAsync ( const std::string &  topic,
const TableViewConfiguration conf,
TableViewCallback  callBack 
)

Async create a table view with given TableViewConfiguration for specified topic.

The TableView provides a key-value map view of a compacted topic. Messages without keys will be ignored.

Parameters
topicThe name of the topic.
confThe TableViewConfiguration object
callBackThe callback that is triggered when the TableView is successfully linked to the topic and the map is built from a message that already exists

◆ getNumberOfConsumers()

uint64_t pulsar::Client::getNumberOfConsumers ( )

Get the number of alive consumers on the current client.

Returns
The number of alive consumers on the current client.

◆ getNumberOfProducers()

uint64_t pulsar::Client::getNumberOfProducers ( )

Get the number of alive producers on the current client.

Returns
The number of alive producers on the current client.

◆ getPartitionsForTopic()

Result pulsar::Client::getPartitionsForTopic ( const std::string &  topic,
std::vector< std::string > &  partitions 
)

Get the list of partitions for a given topic.

If the topic is partitioned, this will return a list of partition names. If the topic is not partitioned, the returned list will contain the topic name itself.

This can be used to discover the partitions and create Reader, Consumer or Producer instances directly on a particular partition.

Parameters
topicthe topic name
Since
2.3.0

◆ getPartitionsForTopicAsync()

void pulsar::Client::getPartitionsForTopicAsync ( const std::string &  topic,
GetPartitionsCallback  callback 
)

Get the list of partitions for a given topic in asynchronous mode.

If the topic is partitioned, this will return a list of partition names. If the topic is not partitioned, the returned list will contain the topic name itself.

This can be used to discover the partitions and create Reader, Consumer or Producer instances directly on a particular partition.

Parameters
topicthe topic name
callbackthe callback that will be invoked when the list of partitions is available
Since
2.3.0

◆ getSchemaInfoAsync()

void pulsar::Client::getSchemaInfoAsync ( const std::string &  topic,
int64_t  version,
std::function< void(Result, const SchemaInfo &)>  callback 
)

Asynchronously get the SchemaInfo of a topic and a specific version.

@topic the topic name

Version
the schema version, see Message::getLongSchemaVersion @callback the callback that is triggered when the SchemaInfo is retrieved successfully or not

◆ shutdown()

void pulsar::Client::shutdown ( )

Perform immediate shutdown of Pulsar client.

Release all resources and close all producer, consumer, and readers without waiting for ongoing operations to complete.

◆ subscribe() [1/4]

Result pulsar::Client::subscribe ( const std::string &  topic,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
Consumer consumer 
)

Subscribe to a given topic and subscription combination with the customized ConsumerConfiguration

Parameters
topicthe topic name
subscriptionNamethe subscription name
[out]consumerthe consumer instance to be returned
Returns
ResultOk if it subscribes to the topic successfully

◆ subscribe() [2/4]

Result pulsar::Client::subscribe ( const std::string &  topic,
const std::string &  subscriptionName,
Consumer consumer 
)

Subscribe to a given topic and subscription combination with the default ConsumerConfiguration

Parameters
topicthe topic name
subscriptionNamethe subscription name
[out]consumerthe consumer instance to be returned
Returns
ResultOk if it subscribes to the topic successfully

◆ subscribe() [3/4]

Result pulsar::Client::subscribe ( const std::vector< std::string > &  topics,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
Consumer consumer 
)

Subscribe to multiple topics with the customized ConsumerConfiguration under the same namespace

Parameters
topicsa list of topic names to subscribe to
subscriptionNamethe subscription name
confthe customized ConsumerConfiguration
[out]consumerthe consumer instance to be returned

◆ subscribe() [4/4]

Result pulsar::Client::subscribe ( const std::vector< std::string > &  topics,
const std::string &  subscriptionName,
Consumer consumer 
)

Subscribe to multiple topics under the same namespace.

Parameters
topicsa list of topic names to subscribe to
subscriptionNamethe subscription name
[out]consumerthe consumer instance to be returned

◆ subscribeAsync() [1/4]

void pulsar::Client::subscribeAsync ( const std::string &  topic,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
SubscribeCallback  callback 
)

Asynchronously subscribe to a given topic and subscription combination with the customized ConsumerConfiguration

Parameters
topicthe topic name
subscriptionNamethe subscription name
confthe customized ConsumerConfiguration
callbackthe callback that is triggered when a given topic and subscription combination with the customized ConsumerConfiguration are asynchronously subscribed successfully or not

◆ subscribeAsync() [2/4]

void pulsar::Client::subscribeAsync ( const std::string &  topic,
const std::string &  subscriptionName,
SubscribeCallback  callback 
)

Asynchronously subscribe to a given topic and subscription combination with the default ConsumerConfiguration

Parameters
topicthe topic name
subscriptionNamethe subscription name
callbackthe callback that is triggered when a given topic and subscription combination with the default ConsumerConfiguration are asynchronously subscribed successfully or not

◆ subscribeAsync() [3/4]

void pulsar::Client::subscribeAsync ( const std::vector< std::string > &  topics,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
SubscribeCallback  callback 
)

Asynchronously subscribe to a list of topics and subscription combination using the customized ConsumerConfiguration

Parameters
topicsthe topic list
subscriptionNamethe subscription name
confthe customized ConsumerConfiguration
callbackthe callback that is triggered when a list of topics and subscription combination using the customized ConsumerConfiguration are asynchronously subscribed successfully or not

◆ subscribeAsync() [4/4]

void pulsar::Client::subscribeAsync ( const std::vector< std::string > &  topics,
const std::string &  subscriptionName,
SubscribeCallback  callback 
)

Asynchronously subscribe to a list of topics and subscription combination using the default ConsumerConfiguration

Parameters
topicsthe topic list
subscriptionNamethe subscription name
callbackthe callback that is triggered when a list of topics and subscription combination using the default ConsumerConfiguration are asynchronously subscribed successfully or not

◆ subscribeWithRegex() [1/2]

Result pulsar::Client::subscribeWithRegex ( const std::string &  regexPattern,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
Consumer consumer 
)

Subscribe to multiple topics (which match given regexPatterns) with the customized ConsumerConfiguration under the same namespace

◆ subscribeWithRegex() [2/2]

Result pulsar::Client::subscribeWithRegex ( const std::string &  regexPattern,
const std::string &  subscriptionName,
Consumer consumer 
)

Subscribe to multiple topics, which match given regexPattern, under the same namespace.

◆ subscribeWithRegexAsync() [1/2]

void pulsar::Client::subscribeWithRegexAsync ( const std::string &  regexPattern,
const std::string &  subscriptionName,
const ConsumerConfiguration conf,
SubscribeCallback  callback 
)

Asynchronously subscribe to multiple topics (which match given regexPatterns) with the customized ConsumerConfiguration under the same namespace

Parameters
regexPatternthe regular expression for topics pattern
subscriptionNamethe subscription name
confthe ConsumerConfiguration
callbackthe callback that is triggered when multiple topics with the customized ConsumerConfiguration under the same namespace are asynchronously subscribed successfully or not

◆ subscribeWithRegexAsync() [2/2]

void pulsar::Client::subscribeWithRegexAsync ( const std::string &  regexPattern,
const std::string &  subscriptionName,
SubscribeCallback  callback 
)

Asynchronously subscribe to multiple topics (which match given regexPatterns) with the default ConsumerConfiguration under the same namespace

See also
subscribeWithRegexAsync(const std::string&, const std::string&, const ConsumerConfiguration&, SubscribeCallback)

The documentation for this class was generated from the following file: