我的情况是我在 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