2828#include < pulsar/Message.h>
2929#include < pulsar/Result.h>
3030#include < pulsar/Schema.h>
31+ #include < pulsar/TypedMessage.h>
3132#include < pulsar/defines.h>
3233
3334#include < functional>
3435#include < memory>
3536
3637#include " BatchReceivePolicy.h"
38+ #include " DeadLetterPolicy.h"
3739
3840namespace pulsar {
3941
4042class Consumer ;
4143class PulsarWrapper ;
44+ class PulsarFriend ;
4245
4346// / Callback definition for non-data operation
4447typedef std::vector<Message> Messages;
@@ -48,7 +51,7 @@ typedef std::function<void(Result, const Messages& msgs)> BatchReceiveCallback;
4851typedef std::function<void (Result result, MessageId messageId)> GetLastMessageIdCallback;
4952
5053// / Callback definition for MessageListener
51- typedef std::function<void (Consumer consumer, const Message& msg)> MessageListener;
54+ typedef std::function<void (Consumer& consumer, const Message& msg)> MessageListener;
5255
5356typedef std::shared_ptr<ConsumerEventListener> ConsumerEventListenerPtr;
5457
@@ -126,6 +129,15 @@ class PULSAR_PUBLIC ConsumerConfiguration {
126129 */
127130 ConsumerConfiguration& setMessageListener (MessageListener messageListener);
128131
132+ template <typename T>
133+ ConsumerConfiguration& setTypedMessageListener (
134+ std::function<void (Consumer&, const TypedMessage<T>&)> listener,
135+ typename TypedMessage<T>::Decoder decoder) {
136+ return setMessageListener ([listener, decoder](Consumer& consumer, const Message& msg) {
137+ listener (consumer, TypedMessage<T>{msg, decoder});
138+ });
139+ }
140+
129141 /* *
130142 * @return the message listener
131143 */
@@ -398,6 +410,42 @@ class PULSAR_PUBLIC ConsumerConfiguration {
398410 */
399411 const BatchReceivePolicy& getBatchReceivePolicy () const ;
400412
413+ /* *
414+ * Set dead letter policy for consumer
415+ *
416+ * By default, some messages are redelivered many times, even to the extent that they can never be
417+ * stopped. By using the dead letter mechanism, messages have the max redelivery count, when they
418+ * exceeding the maximum number of redeliveries. Messages are sent to dead letter topics and acknowledged
419+ * automatically.
420+ *
421+ * You can enable the dead letter mechanism by setting the dead letter policy.
422+ * Example:
423+ *
424+ * <pre>
425+ * * DeadLetterPolicy dlqPolicy = DeadLetterPolicyBuilder()
426+ * .maxRedeliverCount(10)
427+ * .build();
428+ * </pre>
429+ * Default dead letter topic name is {TopicName}-{Subscription}-DLQ.
430+ * To set a custom dead letter topic name
431+ * <pre>
432+ * DeadLetterPolicy dlqPolicy = DeadLetterPolicyBuilder()
433+ * .deadLetterTopic("dlq-topic")
434+ * .maxRedeliverCount(10)
435+ * .initialSubscriptionName("init-sub-name")
436+ * .build();
437+ * </pre>
438+ * @param deadLetterPolicy Default value is empty
439+ */
440+ void setDeadLetterPolicy (const DeadLetterPolicy& deadLetterPolicy);
441+
442+ /* *
443+ * Get dead letter policy.
444+ *
445+ * @return dead letter policy
446+ */
447+ const DeadLetterPolicy& getDeadLetterPolicy () const ;
448+
401449 /* *
402450 * Set whether the subscription status should be replicated.
403451 * The default value is `false`.
@@ -553,7 +601,25 @@ class PULSAR_PUBLIC ConsumerConfiguration {
553601 */
554602 bool isStartMessageIdInclusive () const ;
555603
604+ /* *
605+ * Enable the batch index acknowledgment.
606+ *
607+ * It should be noted that this option can only work when the broker side also enables the batch index
608+ * acknowledgment. See the `acknowledgmentAtBatchIndexLevelEnabled` config in `broker.conf`.
609+ *
610+ * Default: false
611+ *
612+ * @param enabled whether to enable the batch index acknowledgment
613+ */
614+ ConsumerConfiguration& setBatchIndexAckEnabled (bool enabled);
615+
616+ /* *
617+ * The associated getter of setBatchingEnabled
618+ */
619+ bool isBatchIndexAckEnabled () const ;
620+
556621 friend class PulsarWrapper ;
622+ friend class PulsarFriend ;
557623
558624 private:
559625 std::shared_ptr<ConsumerConfigurationImpl> impl_;
0 commit comments