IN- The message type which should write to Pulsar.
@Internal public class KeyHashTopicRouter<IN> extends Object implements TopicRouter<IN>
TopicRoutingMode.MESSAGE_KEY_HASHpolicy, we would use this implementation. We would pick the topic by the message key's hash code. If no message key was provided, we would randomly pick one.
|Constructor and Description|
|Modifier and Type||Method and Description|
Choose the topic by given record & available partition list.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public KeyHashTopicRouter(SinkConfiguration sinkConfiguration)
public String route(IN in, String key, List<String> partitions, PulsarSinkContext context)
in- The record instance which need to be written to Pulsar.
key- The key of the message from
PulsarMessageBuilder.key(String). It could be null, if message doesn't have a key.
partitions- The available partition list. This could be empty if you don't provide any topics in
PulsarSinkBuilder.setTopics(String...). You can return a custom topic, but make sure it should contain a partition index in naming. Using
TopicNameUtils.topicNameWithPartition(String, int)can easily create a topic name with partition index.
context- The context contains useful information for determining the topic.
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.