apache / rocketmq-client-cpp

Apache RocketMQ cpp client
https://rocketmq.apache.org/
Apache License 2.0
366 stars 159 forks source link

DefaultMQPushConsumer callback里面如果部分成功如果处理 #298

Closed he1016060110 closed 4 years ago

he1016060110 commented 4 years ago

对于DefaultMQPushConsumer,代码里面写死了maxNum为32,但是一次消费32条,部分成功,部分失败了,我该怎么在callback里面返回哪些消息成功,哪些需要reconsume,因为默认status只有一个,也就是要么全成功,要么全失败。

he1016060110 commented 4 years ago

我看到consumeMessage传的msg引用 ConsumeStatus consumeMessage(const std::vector& msgs) = 0; 我应该可以把这个vector改了,然后传RECONSUME_LATER吧

ShannonDing commented 4 years ago

once the RECONSUME_LATER return, all the messages in the vector will be sent back to the broker. you should do not change the message vectors. and more, Issues are generally used for bug reports and feature requests, so if you have any questions about Apache RocketMQ, it is recommended to discuss it on the mailing list first, the mailing list address. I will close the Issue first, but please feel free to reopen it if you have any other issues.

ifplusor commented 4 years ago

You can set consume batch size to 1 by DefaultMQPushConsumer::setConsumeMessageBatchMaxSize.

he1016060110 commented 4 years ago

You can set consume batch size to 1 by DefaultMQPushConsumer::setConsumeMessageBatchMaxSize.

tried.the concurrency is so low.so i suggest that consumeMessage should contains two params,like solution below consumeMessage(const std::vector& msgs, std::vecotr & batchStatus) so that we can send message back according to the different status of every message of the batch.

ifplusor commented 4 years ago

@he1016060110 Call sendMessageBack by yourself, then return CONSUME_SUCCESS. But latest client not expose sendMessageBack in DefaultMQPushConsumer. Add it, and call DefaultMQPushConsumerImpl#sendMessageBack

ifplusor commented 4 years ago

@ShannonDing Can we expose sendMessageBack in DefaultMQPushConsumer?

ShannonDing commented 4 years ago

IMO, It is not recommended to open this capability. In order to deal with simplicity and ensure the reliability and order as much as possible, the logic of sending back the broker is handled internally by the client and guarantees the success of the return. If this function is opened, it means that the failure to send back is uncontrollable, which increases the risk of message loss. In addition, if you don't want to report errors in batches, you can directly reply to CONSUMER_SUCCESS and re-deliver the failed message as a new message to this topic through a new independent producer.

he1016060110 commented 4 years ago

I can do this ,although it's not elegant.And I still hold the point that there should be status vector param for consumeMessage.