pulsar-client-cpp
|
#include <ProducerConfiguration.h>
Public Types | |
enum | PartitionsRoutingMode { UseSinglePartition , RoundRobinDistribution , CustomPartition } |
enum | HashingScheme { Murmur3_32Hash , BoostHash , JavaStringHash } |
enum | BatchingType { DefaultBatching , KeyBasedBatching } |
enum | ProducerAccessMode { Shared = 0 , Exclusive = 1 , WaitForExclusive = 2 , ExclusiveWithFencing = 3 } |
Public Member Functions | |
ProducerConfiguration (const ProducerConfiguration &) | |
ProducerConfiguration & | operator= (const ProducerConfiguration &) |
ProducerConfiguration & | setProducerName (const std::string &producerName) |
const std::string & | getProducerName () const |
ProducerConfiguration & | setSchema (const SchemaInfo &schemaInfo) |
const SchemaInfo & | getSchema () const |
ProducerConfiguration & | setSendTimeout (int sendTimeoutMs) |
int | getSendTimeout () const |
ProducerConfiguration & | setInitialSequenceId (int64_t initialSequenceId) |
int64_t | getInitialSequenceId () const |
ProducerConfiguration & | setCompressionType (CompressionType compressionType) |
CompressionType | getCompressionType () const |
ProducerConfiguration & | setMaxPendingMessages (int maxPendingMessages) |
int | getMaxPendingMessages () const |
ProducerConfiguration & | setMaxPendingMessagesAcrossPartitions (int maxPendingMessagesAcrossPartitions) |
int | getMaxPendingMessagesAcrossPartitions () const |
ProducerConfiguration & | setPartitionsRoutingMode (const PartitionsRoutingMode &mode) |
PartitionsRoutingMode | getPartitionsRoutingMode () const |
ProducerConfiguration & | setMessageRouter (const MessageRoutingPolicyPtr &router) |
const MessageRoutingPolicyPtr & | getMessageRouterPtr () const |
ProducerConfiguration & | setHashingScheme (const HashingScheme &scheme) |
HashingScheme | getHashingScheme () const |
ProducerConfiguration & | setLazyStartPartitionedProducers (bool) |
bool | getLazyStartPartitionedProducers () const |
ProducerConfiguration & | setBlockIfQueueFull (bool) |
bool | getBlockIfQueueFull () const |
ProducerConfiguration & | setBatchingEnabled (const bool &batchingEnabled) |
const bool & | getBatchingEnabled () const |
ProducerConfiguration & | setBatchingMaxMessages (const unsigned int &batchingMaxMessages) |
const unsigned int & | getBatchingMaxMessages () const |
ProducerConfiguration & | setBatchingMaxAllowedSizeInBytes (const unsigned long &batchingMaxAllowedSizeInBytes) |
const unsigned long & | getBatchingMaxAllowedSizeInBytes () const |
ProducerConfiguration & | setBatchingMaxPublishDelayMs (const unsigned long &batchingMaxPublishDelayMs) |
const unsigned long & | getBatchingMaxPublishDelayMs () const |
ProducerConfiguration & | setBatchingType (BatchingType batchingType) |
BatchingType | getBatchingType () const |
const CryptoKeyReaderPtr | getCryptoKeyReader () const |
ProducerConfiguration & | setCryptoKeyReader (CryptoKeyReaderPtr cryptoKeyReader) |
ProducerCryptoFailureAction | getCryptoFailureAction () const |
ProducerConfiguration & | setCryptoFailureAction (ProducerCryptoFailureAction action) |
const std::set< std::string > & | getEncryptionKeys () const |
bool | isEncryptionEnabled () const |
ProducerConfiguration & | addEncryptionKey (std::string key) |
bool | hasProperty (const std::string &name) const |
const std::string & | getProperty (const std::string &name) const |
std::map< std::string, std::string > & | getProperties () const |
ProducerConfiguration & | setProperty (const std::string &name, const std::string &value) |
ProducerConfiguration & | setProperties (const std::map< std::string, std::string > &properties) |
ProducerConfiguration & | setChunkingEnabled (bool chunkingEnabled) |
bool | isChunkingEnabled () const |
ProducerConfiguration & | setAccessMode (const ProducerAccessMode &accessMode) |
ProducerAccessMode | getAccessMode () const |
ProducerConfiguration & | intercept (const std::vector< ProducerInterceptorPtr > &interceptors) |
const std::vector< ProducerInterceptorPtr > & | getInterceptors () const |
Friends | |
class | PulsarWrapper |
class | ConsumerImpl |
class | ProducerImpl |
Class that holds the configuration for a producer
Enumerator | |
---|---|
Shared | By default multiple producers can publish on a topic. |
Exclusive | Require exclusive access for producer. Fail immediately if there's already a producer connected. |
WaitForExclusive | Producer creation is pending until it can acquire exclusive access. |
ExclusiveWithFencing | Acquire exclusive access for the producer. Any existing producer will be removed and invalidated immediately. |
ProducerConfiguration & pulsar::ProducerConfiguration::addEncryptionKey | ( | std::string | key | ) |
Add public encryption key, used by producer to encrypt the data key.
At the time of producer creation, Pulsar client checks if there are keys added to encryptionKeys. If keys are found, a callback getKey(String keyName) is invoked against each key to load the values of the key. Application should implement this callback to return the key in pkcs8 format. If compression is enabled, message is encrypted after compression. If batch messaging is enabled, the batched message is encrypted.
@key the encryption key to add
ProducerAccessMode pulsar::ProducerConfiguration::getAccessMode | ( | ) | const |
Get the type of access mode that the producer requires on the topic.
const bool & pulsar::ProducerConfiguration::getBatchingEnabled | ( | ) | const |
Return the flag whether automatic message batching is enabled or not for the producer.
const unsigned long & pulsar::ProducerConfiguration::getBatchingMaxAllowedSizeInBytes | ( | ) | const |
The getter associated with setBatchingMaxAllowedSizeInBytes().
const unsigned int & pulsar::ProducerConfiguration::getBatchingMaxMessages | ( | ) | const |
The getter associated with setBatchingMaxMessages().
const unsigned long & pulsar::ProducerConfiguration::getBatchingMaxPublishDelayMs | ( | ) | const |
The getter associated with setBatchingMaxPublishDelayMs().
BatchingType pulsar::ProducerConfiguration::getBatchingType | ( | ) | const |
bool pulsar::ProducerConfiguration::getBlockIfQueueFull | ( | ) | const |
CompressionType pulsar::ProducerConfiguration::getCompressionType | ( | ) | const |
The getter associated with setCompressionType().
ProducerCryptoFailureAction pulsar::ProducerConfiguration::getCryptoFailureAction | ( | ) | const |
The getter associated with setCryptoFailureAction().
const CryptoKeyReaderPtr pulsar::ProducerConfiguration::getCryptoKeyReader | ( | ) | const |
The getter associated with setCryptoKeyReader().
const std::set< std::string > & pulsar::ProducerConfiguration::getEncryptionKeys | ( | ) | const |
HashingScheme pulsar::ProducerConfiguration::getHashingScheme | ( | ) | const |
The getter associated with setHashingScheme().
int64_t pulsar::ProducerConfiguration::getInitialSequenceId | ( | ) | const |
The getter associated with setInitialSequenceId().
bool pulsar::ProducerConfiguration::getLazyStartPartitionedProducers | ( | ) | const |
The getter associated with setLazyStartPartitionedProducers()
int pulsar::ProducerConfiguration::getMaxPendingMessages | ( | ) | const |
The getter associated with setMaxPendingMessages().
int pulsar::ProducerConfiguration::getMaxPendingMessagesAcrossPartitions | ( | ) | const |
const MessageRoutingPolicyPtr & pulsar::ProducerConfiguration::getMessageRouterPtr | ( | ) | const |
The getter associated with setMessageRouter().
PartitionsRoutingMode pulsar::ProducerConfiguration::getPartitionsRoutingMode | ( | ) | const |
The getter associated with setPartitionsRoutingMode().
const std::string & pulsar::ProducerConfiguration::getProducerName | ( | ) | const |
The getter associated with setProducerName().
std::map< std::string, std::string > & pulsar::ProducerConfiguration::getProperties | ( | ) | const |
Get all the properties attached to this producer.
const std::string & pulsar::ProducerConfiguration::getProperty | ( | const std::string & | name | ) | const |
Get the value of a specific property
name | the name of the property |
const SchemaInfo & pulsar::ProducerConfiguration::getSchema | ( | ) | const |
int pulsar::ProducerConfiguration::getSendTimeout | ( | ) | const |
Get the send timeout is milliseconds.
If a message is not acknowledged by the server before the sendTimeout expires, an error will be reported.
If the timeout is zero, there will be no timeout.
bool pulsar::ProducerConfiguration::hasProperty | ( | const std::string & | name | ) | const |
Check whether the producer has a specific property attached.
name | the name of the property to check |
bool pulsar::ProducerConfiguration::isChunkingEnabled | ( | ) | const |
The getter associated with setChunkingEnabled().
bool pulsar::ProducerConfiguration::isEncryptionEnabled | ( | ) | const |
ProducerConfiguration & pulsar::ProducerConfiguration::setAccessMode | ( | const ProducerAccessMode & | accessMode | ) |
Set the type of access mode that the producer requires on the topic.
accessMode | The type of access to the topic that the producer requires |
ProducerConfiguration & pulsar::ProducerConfiguration::setBatchingEnabled | ( | const bool & | batchingEnabled | ) |
Control whether automatic batching of messages is enabled or not for the producer.
Default: true
When automatic batching is enabled, multiple calls to Producer::sendAsync can result in a single batch to be sent to the broker, leading to better throughput, especially when publishing small messages. If compression is enabled, messages are compressed at the batch level, leading to a much better compression ratio for similar headers or contents.
When the default batch delay is set to 10 ms and the default batch size is 1000 messages.
ProducerConfiguration & pulsar::ProducerConfiguration::setBatchingMaxAllowedSizeInBytes | ( | const unsigned long & | batchingMaxAllowedSizeInBytes | ) |
Set the max size of messages permitted in a batch. Default value: 128 KB. If you set this option to a value greater than 1, messages are queued until this threshold is reached or batch interval has elapsed.
All messages in a batch are published as a single batch message. The consumer is delivered individual messages in the batch in the same order they are enqueued.
batchingMaxAllowedSizeInBytes |
ProducerConfiguration & pulsar::ProducerConfiguration::setBatchingMaxMessages | ( | const unsigned int & | batchingMaxMessages | ) |
Set the max number of messages permitted in a batch. Default value: 1000. If you set this option to a value greater than 1, messages are queued until this threshold is reached or batch interval has elapsed.
All messages in a batch are published as a single batch message. The consumer is delivered individual messages in the batch in the same order they are enqueued.
batchMessagesMaxMessagesPerBatch | max number of messages permitted in a batch |
ProducerConfiguration & pulsar::ProducerConfiguration::setBatchingMaxPublishDelayMs | ( | const unsigned long & | batchingMaxPublishDelayMs | ) |
Set the max time for message publish delay permitted in a batch. Default value: 10 ms.
batchingMaxPublishDelayMs | max time for message publish delay permitted in a batch. |
ProducerConfiguration & pulsar::ProducerConfiguration::setBatchingType | ( | BatchingType | batchingType | ) |
Default: DefaultBatching
ProducerConfiguration & pulsar::ProducerConfiguration::setBlockIfQueueFull | ( | bool | ) |
The setter associated with getBlockIfQueueFull()
ProducerConfiguration & pulsar::ProducerConfiguration::setChunkingEnabled | ( | bool | chunkingEnabled | ) |
If message size is higher than allowed max publish-payload size by broker then enableChunking helps producer to split message into multiple chunks and publish them to broker separately in order. So, it allows client to successfully publish large size of messages in pulsar.
Set it true to enable this feature. If so, you must disable batching (see setBatchingEnabled), otherwise the producer creation will fail.
There are some other recommendations when it's enabled:
Default: false
chunkingEnabled | whether chunking is enabled |
ProducerConfiguration & pulsar::ProducerConfiguration::setCompressionType | ( | CompressionType | compressionType | ) |
Set the compression type for the producer.
By default, message payloads are not compressed. Supported compression types are:
CompressionNone
: No compression CompressionLZ4
: LZ4 Compression https://lz4.github.io/lz4/ CompressionZLib
: ZLib Compression http://zlib.net/ CompressionZSTD
: Zstandard Compression https://facebook.github.io/zstd/ (Since Pulsar 2.3. Zstd cannot be used if consumer applications are not in version >= 2.3 as well) CompressionSNAPPY
: Snappy Compression https://google.github.io/snappy/ (Since Pulsar 2.4. Snappy cannot be used if consumer applications are not in version >= 2.4 as well) ProducerConfiguration & pulsar::ProducerConfiguration::setCryptoFailureAction | ( | ProducerCryptoFailureAction | action | ) |
Sets the ProducerCryptoFailureAction to the value specified.
action | the action taken by the producer in case of encryption failures. |
ProducerConfiguration & pulsar::ProducerConfiguration::setCryptoKeyReader | ( | CryptoKeyReaderPtr | cryptoKeyReader | ) |
ProducerConfiguration & pulsar::ProducerConfiguration::setHashingScheme | ( | const HashingScheme & | scheme | ) |
Set the hashing scheme, which is a standard hashing function available when choosing the partition used for a particular message.
Default: HashingScheme::BoostHash
Standard hashing functions available are:
HashingScheme::JavaStringHash
: Java String.hashCode()
(Default). HashingScheme::BoostHash
: Use Boost hashing function. HashingScheme::Murmur3_32Hash
: Use [Murmur3 hashing function](https://en.wikipedia.org/wiki/MurmurHash"). scheme | hashing scheme. |
ProducerConfiguration & pulsar::ProducerConfiguration::setInitialSequenceId | ( | int64_t | initialSequenceId | ) |
Set the baseline of the sequence ID for messages published by the producer.
The first message uses (initialSequenceId + 1) as its sequence ID and subsequent messages are assigned incremental sequence IDs.
Default: -1, which means the first message's sequence ID is 0.
initialSequenceId | the initial sequence ID for the producer. |
ProducerConfiguration & pulsar::ProducerConfiguration::setLazyStartPartitionedProducers | ( | bool | ) |
This config affects producers of partitioned topics only. It controls whether producers register and connect immediately to the owner broker of each partition or start lazily on demand. The internal producer of one partition is always started eagerly, chosen by the routing policy, but the internal producers of any additional partitions are started on demand, upon receiving their first message. Using this mode can reduce the strain on brokers for topics with large numbers of partitions and when the SinglePartition routing policy is used without keyed messages. Because producer connection can be on demand, this can produce extra send latency for the first messages of a given partition.
true/false | as to whether to start partition producers lazily |
ProducerConfiguration & pulsar::ProducerConfiguration::setMaxPendingMessages | ( | int | maxPendingMessages | ) |
Set the max size of the queue holding the messages pending to receive an acknowledgment from the broker.
When the queue is full, by default, all calls to Producer::send and Producer::sendAsync would fail unless blockIfQueueFull is set to true. Use setBlockIfQueueFull
to change the blocking behavior.
Default: 1000
maxPendingMessages | max number of pending messages. |
ProducerConfiguration & pulsar::ProducerConfiguration::setMaxPendingMessagesAcrossPartitions | ( | int | maxPendingMessagesAcrossPartitions | ) |
Set the number of max pending messages across all the partitions
This setting will be used to lower the max pending messages for each partition (setMaxPendingMessages(int)
), if the total exceeds the configured value.
Default: 50000
maxPendingMessagesAcrossPartitions |
ProducerConfiguration & pulsar::ProducerConfiguration::setMessageRouter | ( | const MessageRoutingPolicyPtr & | router | ) |
Set a custom message routing policy by passing an implementation of MessageRouter.
messageRouter | message router. |
ProducerConfiguration & pulsar::ProducerConfiguration::setPartitionsRoutingMode | ( | const PartitionsRoutingMode & | mode | ) |
Set the message routing modes for partitioned topics.
Default: UseSinglePartition
PartitionsRoutingMode | partition routing mode. |
ProducerConfiguration & pulsar::ProducerConfiguration::setProducerName | ( | const std::string & | producerName | ) |
Set the producer name which could be assigned by the system or specified by the client.
producerName | producer name. |
ProducerConfiguration & pulsar::ProducerConfiguration::setProperties | ( | const std::map< std::string, std::string > & | properties | ) |
Add all the properties in the provided map
ProducerConfiguration & pulsar::ProducerConfiguration::setProperty | ( | const std::string & | name, |
const std::string & | value | ||
) |
Sets a new property on the producer
name | the name of the property |
value | the associated value |
ProducerConfiguration & pulsar::ProducerConfiguration::setSchema | ( | const SchemaInfo & | schemaInfo | ) |
Declare the schema of the data that will be published by this producer.
The schema will be checked against the schema of the topic, and it will fail if it's not compatible, though the client library will not perform any validation that the actual message payload are conforming to the specified schema.
For all purposes, this
schemaInfo |
ProducerConfiguration & pulsar::ProducerConfiguration::setSendTimeout | ( | int | sendTimeoutMs | ) |
The getter associated with getSendTimeout()