简体   繁体   English

Pulsar 消息总线:我们可以为每个主题配置消息保留吗?

[英]Pulsar message bus: Can we configure message retention per topic?

We have a usecase where our messages processor, processes messages with very complex calculations on messages from few topics.我们有一个用例,我们的消息处理器通过对来自少数主题的消息进行非常复杂的计算来处理消息。 These calculations are not finishing within the rention period configured.这些计算未在配置的租用期内完成。 Instead of increaseing message retention globally for all topics can we set this for the few topics where we need messages to be retained for more time?我们可以为少数几个需要将消息保留更长时间的主题设置此设置,而不是增加所有主题的全局消息保留时间吗? Message retention per topic is possible?每个主题的消息保留是可能的吗?

This is exactly the use case that namespaces were designed for.这正是命名空间设计的用例。 In Pulsar, a namespace is an administrative unit within a tenant that contains a subset of topics.在 Pulsar 中,命名空间是租户中包含主题子集的管理单元。 The configuration policies set on a namespace apply to all the topics created in that namespace.在命名空间上设置的配置策略适用于在该命名空间中创建的所有主题。 The best way to address this issue is use the either the REST API or the pulsar-admin CLI tool to create a new namespace, eg解决此问题的最佳方法是使用 REST API 或pulsar-admin CLI 工具来创建新的命名空间,例如

pulsar-admin namespaces create <current-tenant>/<a-new-namespace>

Once you have the new namespace, you can then configure the retention policy for the new namespace using the CLI tool, eg一旦有了新的命名空间,您就可以使用 CLI 工具为新命名空间配置保留策略,例如

$ pulsar-admin namespaces set-retention <current-tenant>/<a-new-namespace> \
  --size -1 \
  --time -1

Finally, you will want to re-create the topics in the new namespace, and change your code to use these new topics.最后,您需要在新命名空间中重新创建主题,并更改您的代码以使用这些新主题。

If you use a subscription on the topic, then you don't have to worry about message retention.如果您使用该主题的订阅,则不必担心消息保留。 Messages in a subscription backlog are not removed until they are acknowledged, regardless of the retention setting.订阅积压中的消息在被确认之前不会被删除,无论保留设置如何。 Just use the Consumer interface in the client and acknowledge each message after the calculations are done.只需在客户端使用 Consumer 接口,并在计算完成后确认每条消息。

For more details about retention and subscription backlogs, see this Understanding Pulsar Message TTL, Backlog, and Retention有关保留和订阅积压的更多详细信息,请参阅了解 Pulsar 消息 TTL、积压和保留

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 pulsar 消息侦听器进行多线程处理 - Multithreading with pulsar message listeners 消费者应用程序使用消息后,如何从主题队列中删除脉冲星消息? - how to remove the pulsar message from queue for a topic after message is consumed by a consumer application? 为每条消息的 HttpRequestExecutingMessageHandler 配置 RestTemplate - Configure RestTemplate for HttpRequestExecutingMessageHandler per message 如何在 Pulsar 中按键获取消息 - How to get message by key in Pulsar 我们如何使用 java 对 azure 服务总线队列中存在的消息添加延迟? - How can we add a delay on the message which is present in azure service bus queue using java? Camel JMS:连接到主题时如何配置自定义消息侦听器 - Camel JMS : how to configure custom message listener when connecting to a topic 每个主题在集​​群中运行的每个侦听器仅消耗一次消息 - Consume message only once from Topic per listeners running in cluster 通过Azure Java SDK向服务总线主题发送消息时出现500 Internal Server Error - 500 Internal Server Error while sending a message to a Service Bus topic through Azure Java SDK 如何在使用 Spring 创建期间配置 kafka 主题保留策略? - How to configure kafka topic retention policy during creation with Spring? 消息未传递给 Kafka 主题 - Message is not passing to Kafka topic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM