IN
- The message type which should write to Pulsar.@Internal public class KeyHashTopicRouter<IN> extends Object implements TopicRouter<IN>
TopicRoutingMode.MESSAGE_KEY_HASH
policy, 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 |
---|
KeyHashTopicRouter(SinkConfiguration sinkConfiguration) |
Modifier and Type | Method and Description |
---|---|
String |
route(IN in,
String key,
List<String> partitions,
PulsarSinkContext context)
Choose the topic by given record & available partition list.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
open
public KeyHashTopicRouter(SinkConfiguration sinkConfiguration)
public String route(IN in, String key, List<String> partitions, PulsarSinkContext context)
TopicRouter
route
in interface TopicRouter<IN>
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–2024 The Apache Software Foundation. All rights reserved.