My situation is that I have compacted topic in Pulsar ( https://pulsar.apache.org/docs/en/concepts-topic-compaction/ ). With producer I am sending messages with key. Is it possible to get a specific message by using key with consumer?
My code:
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 can be used to query data directly using Presto.
Alternatively you can use Bookkeeper Table API which is low level and should be avoided without a strong justification
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.