繁体   English   中英

如何在 Pulsar 中按键获取消息

[英]How to get message by key in Pulsar

我的情况是我在 Pulsar 中压缩了主题( https://pulsar.apache.org/docs/en/concepts-topic-compaction/ )。 与生产者一起,我正在发送带有密钥的消息。 是否可以通过与消费者一起使用密钥来获取特定消息?

我的代码:

Producer<byte[]> producer = client.newProducer()
            .topic(TOPIC_NAME)
            .compressionType(CompressionType.LZ4).create();

    String name = "name";
    String lastName = "lastname";

    byte[] nameBytes = name.getBytes();
    byte[] lastNameBytes = lastName.getBytes();

    producer.newMessage().key("key1").value(nameBytes).send();
    producer.newMessage().key("key2").value(lastNameBytes).send();

    Consumer<byte[]> consumer = client.newConsumer()
            .topic(TOPIC_NAME)
            .readCompacted(true)
            .subscriptionName("test")
            .subscribe();

    // need to get message by key

Pulsar SQL 可用于直接使用 Presto 查询数据。

或者,您可以使用 Bookkeeper Table API这是低级别的,应该避免没有充分的理由

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM