Apache pulsar 如何将TTL(生存时间)应用于命名空间?

Apache pulsar 如何将TTL(生存时间)应用于命名空间?,apache-pulsar,Apache Pulsar,ApachePulsar有一个TTL特性,如官方文档主题下所述。但是,我无法确定在配置中的何处设置此检查的频率。使用带有自定义名称空间的标准bin/pulsar standalone命令,ttl配置为5秒bin/pulsar admin名称空间设置消息ttl public/ttl test--messageTTL 5 我可以看到消息只有在设置的时间间隔后才会过期,并且以下日志消息会打印到控制台: 15:11:59.337[脉冲星-msg-EXIT-monitor-52-1]信息 org.apac

ApachePulsar有一个TTL特性,如官方文档主题下所述。但是,我无法确定在配置中的何处设置此检查的频率。使用带有自定义名称空间的标准
bin/pulsar standalone
命令,ttl配置为5秒
bin/pulsar admin名称空间设置消息ttl public/ttl test--messageTTL 5

我可以看到消息只有在设置的时间间隔后才会过期,并且以下日志消息会打印到控制台:

15:11:59.337[脉冲星-msg-EXIT-monitor-52-1]信息 org.apache.pulsar.broker.service.persistent.PersistentMessageExpiryMonitor -[persistent://public/ttl-test/my-topic][spark shell]启动消息到期检查,ttl=5秒


我的问题的关键是:如何提高检查消息是否超过TTL的速率?

代理中的配置
messageexpiryCheckKinterValinMinutes
决定了检查命名空间主题是否有过期消息的频率


根据

上的官方文档,使用set message ttl命令并指定名称空间名称(对于持久主题,默认为public/default)和时间

bin/pulsar-admin namespaces set-message-ttl public/default --messageTTL 120
生产者和消费者实现ttl(python客户端)的示例代码

您可以使用send方法发送多条消息。两个类中的主题名称应相同

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe("my-topic-reader1", "my-subscription")

//receive all the messages.whatever we publish
msg = consumer.receive()
print("Received message '{}' id='{}'".format(msg.data(), msg.message_id()))

//Here we are not acknowledge all the messages.

//close the consumer and client
consumer.close()
client.close()
在120秒内,我们再次打开客户端和消费者,并尝试读取相同的消息,这不是发布。我们再次关闭客户端和消费者


稍后(120秒后),我们将再次打开客户端和消费者,然后尝试接收消息。但它不应该出现。在这种情况下,你将获得生存的时间

当我写下我的问题时,我意识到我需要寻找的是什么,但我还是发布了它,并添加了我找到的答案。
import pulsar
client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe("my-topic-reader1", "my-subscription")

//receive all the messages.whatever we publish
msg = consumer.receive()
print("Received message '{}' id='{}'".format(msg.data(), msg.message_id()))

//Here we are not acknowledge all the messages.

//close the consumer and client
consumer.close()
client.close()