@@ -40,16 +40,20 @@ using namespace pulsar;
4040MultiTopicsConsumerImpl::MultiTopicsConsumerImpl (ClientImplPtr client, TopicNamePtr topicName,
4141 int numPartitions, const std::string& subscriptionName,
4242 const ConsumerConfiguration& conf,
43- LookupServicePtr lookupServicePtr)
43+ LookupServicePtr lookupServicePtr,
44+ const Commands::SubscriptionMode subscriptionMode,
45+ boost::optional<MessageId> startMessageId)
4446 : MultiTopicsConsumerImpl(client, {topicName->toString ()}, subscriptionName, topicName, conf,
45- lookupServicePtr) {
47+ lookupServicePtr, subscriptionMode, startMessageId ) {
4648 topicsPartitions_[topicName->toString ()] = numPartitions;
4749}
4850
4951MultiTopicsConsumerImpl::MultiTopicsConsumerImpl (ClientImplPtr client, const std::vector<std::string>& topics,
5052 const std::string& subscriptionName, TopicNamePtr topicName,
5153 const ConsumerConfiguration& conf,
52- LookupServicePtr lookupServicePtr)
54+ LookupServicePtr lookupServicePtr,
55+ const Commands::SubscriptionMode subscriptionMode,
56+ boost::optional<MessageId> startMessageId)
5357 : ConsumerImplBase(client, topicName ? topicName->toString () : "EmptyTopics",
5458 Backoff(milliseconds(100 ), seconds(60 ), milliseconds(0 )), conf,
5559 client->getListenerExecutorProvider()->get()),
@@ -60,7 +64,9 @@ MultiTopicsConsumerImpl::MultiTopicsConsumerImpl(ClientImplPtr client, const std
6064 messageListener_(conf.getMessageListener()),
6165 lookupServicePtr_(lookupServicePtr),
6266 numberTopicPartitions_(std::make_shared<std::atomic<int >>(0 )),
63- topics_(topics) {
67+ topics_(topics),
68+ subscriptionMode_(subscriptionMode),
69+ startMessageId_(startMessageId) {
6470 std::stringstream consumerStrStream;
6571 consumerStrStream << " [Muti Topics Consumer: "
6672 << " TopicName - " << topic_ << " - Subscription - " << subscriptionName << " ]" ;
@@ -226,7 +232,7 @@ void MultiTopicsConsumerImpl::subscribeTopicPartitions(int numPartitions, TopicN
226232 // We don't have to add partition-n suffix
227233 consumer = std::make_shared<ConsumerImpl>(client, topicName->toString (), subscriptionName_, config,
228234 topicName->isPersistent (), internalListenerExecutor, true ,
229- NonPartitioned);
235+ NonPartitioned, subscriptionMode_, startMessageId_ );
230236 consumer->getConsumerCreatedFuture ().addListener (std::bind (
231237 &MultiTopicsConsumerImpl::handleSingleConsumerCreated, get_shared_this_ptr (),
232238 std::placeholders::_1, std::placeholders::_2, partitionsNeedCreate, topicSubResultPromise));
@@ -239,7 +245,7 @@ void MultiTopicsConsumerImpl::subscribeTopicPartitions(int numPartitions, TopicN
239245 std::string topicPartitionName = topicName->getTopicPartitionName (i);
240246 consumer = std::make_shared<ConsumerImpl>(client, topicPartitionName, subscriptionName_, config,
241247 topicName->isPersistent (), internalListenerExecutor,
242- true , Partitioned);
248+ true , Partitioned, subscriptionMode_, startMessageId_ );
243249 consumer->getConsumerCreatedFuture ().addListener (std::bind (
244250 &MultiTopicsConsumerImpl::handleSingleConsumerCreated, get_shared_this_ptr (),
245251 std::placeholders::_1, std::placeholders::_2, partitionsNeedCreate, topicSubResultPromise));
@@ -686,7 +692,12 @@ void MultiTopicsConsumerImpl::acknowledgeAsync(const MessageIdList& messageIdLis
686692}
687693
688694void MultiTopicsConsumerImpl::acknowledgeCumulativeAsync (const MessageId& msgId, ResultCallback callback) {
689- callback (ResultOperationNotSupported);
695+ msgId.getTopicName ();
696+ auto optConsumer = consumers_.find (msgId.getTopicName ());
697+ if (optConsumer) {
698+ unAckedMessageTrackerPtr_->removeMessagesTill (msgId);
699+ optConsumer.value ()->acknowledgeCumulativeAsync (msgId, callback);
700+ }
690701}
691702
692703void MultiTopicsConsumerImpl::negativeAcknowledge (const MessageId& msgId) {
@@ -1047,3 +1058,35 @@ void MultiTopicsConsumerImpl::cancelTimers() noexcept {
10471058 partitionsUpdateTimer_->cancel (ec);
10481059 }
10491060}
1061+
1062+ void MultiTopicsConsumerImpl::hasMessageAvailableAsync (HasMessageAvailableCallback callback) {
1063+ if (incomingMessagesSize_ > 0 ) {
1064+ callback (ResultOk, true );
1065+ return ;
1066+ }
1067+
1068+ auto hasMessageAvailable = std::make_shared<std::atomic<bool >>();
1069+ auto needCallBack = std::make_shared<std::atomic<int >>(consumers_.size ());
1070+ auto self = get_shared_this_ptr ();
1071+
1072+ consumers_.forEachValue ([self, needCallBack, callback, hasMessageAvailable](ConsumerImplPtr consumer) {
1073+ consumer->hasMessageAvailableAsync (
1074+ [self, needCallBack, callback, hasMessageAvailable](Result result, bool hasMsg) {
1075+ if (result != ResultOk) {
1076+ LOG_ERROR (" Filed when acknowledge list: " << result);
1077+ // set needCallBack is -1 to avoid repeated callback.
1078+ needCallBack->store (-1 );
1079+ callback (result, false );
1080+ return ;
1081+ }
1082+
1083+ if (hasMsg) {
1084+ hasMessageAvailable->store (hasMsg);
1085+ }
1086+
1087+ if (--(*needCallBack) == 0 ) {
1088+ callback (result, hasMessageAvailable->load () || self->incomingMessagesSize_ > 0 );
1089+ }
1090+ });
1091+ });
1092+ }
0 commit comments