@Override public boolean hasKey() { return msg.hasKey(); }
@Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { // If the message has a key, it supersedes the single partition routing policy if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; }
@Override public int choosePartition(Message<?> msg, TopicMetadata topicMetadata) { // If the message has a key, it supersedes the round robin routing policy if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), topicMetadata.numPartitions()); } if (isBatchingEnabled) { // if batching is enabled, choose partition on `maxBatchingDelayMs` boundary. long currentMs = clock.millis(); return signSafeMod(currentMs / maxBatchingDelayMs + startPtnIdx, topicMetadata.numPartitions()); } else { return signSafeMod(PARTITION_INDEX_UPDATER.getAndIncrement(this), topicMetadata.numPartitions()); } }
@Override public boolean hasKey() { return msg.hasKey(); }
@Override public Optional<String> getKey() { if (message.hasKey()) { return Optional.of(message.getKey()); } else { return Optional.empty(); } }
@Override public int choosePartition(Message<?> msg, TopicMetadata metadata) { // If the message has a key, it supersedes the single partition routing policy if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), metadata.numPartitions()); } return partitionIndex; }
@Override public int choosePartition(Message msg, TopicMetadata metadata) { // if key is specified, we should use key as routing; // if key is not specified and no sequence id is provided, not an effectively-once publish, use the default // round-robin routing. if (msg.hasKey() || msg.getSequenceId() < 0) { // TODO: the message key routing is problematic at this moment. // https://github.com/apache/pulsar/pull/1029 is fixing that. return super.choosePartition(msg, metadata); } // if there is no key and sequence id is provided, it is an effectively-once publish, we need to ensure // for a given message it always go to one partition, so we use sequence id to do a deterministic routing. return (int) (msg.getSequenceId() % metadata.numPartitions()); }
dm.eventTime = DateFormatter.format(msg.getEventTime()); if (msg.hasKey()) { dm.key = msg.getKey();
dm.eventTime = DateFormatter.format(msg.getEventTime()); if (msg.hasKey()) { dm.key = msg.getKey();
@Override public int choosePartition(Message<?> msg, TopicMetadata topicMetadata) { // If the message has a key, it supersedes the round robin routing policy if (msg.hasKey()) { return signSafeMod(hash.makeHash(msg.getKey()), topicMetadata.numPartitions()); } if (isBatchingEnabled) { // if batching is enabled, choose partition on `maxBatchingDelayMs` boundary. long currentMs = clock.millis(); return signSafeMod(currentMs / maxBatchingDelayMs + startPtnIdx, topicMetadata.numPartitions()); } else { return signSafeMod(PARTITION_INDEX_UPDATER.getAndIncrement(this), topicMetadata.numPartitions()); } }