/** * Choose a partition based on msg and the topic metadata. * * @param msg message to route * @param metadata topic metadata * @return the partition to route the message. * @since 1.22.0 */ default int choosePartition(Message<?> msg, TopicMetadata metadata) { return choosePartition(msg); }
@Override CompletableFuture<MessageId> internalSendAsync(Message<T> message) { switch (getState()) { case Ready: case Connecting: break; // Ok case Closing: case Closed: return FutureUtil.failedFuture(new PulsarClientException.AlreadyClosedException("Producer already closed")); case Terminated: return FutureUtil.failedFuture(new PulsarClientException.TopicTerminatedException("Topic was terminated")); case Failed: case Uninitialized: return FutureUtil.failedFuture(new PulsarClientException.NotConnectedException()); } int partition = routerPolicy.choosePartition(message, topicMetadata); checkArgument(partition >= 0 && partition < topicMetadata.numPartitions(), "Illegal partition index chosen by the message routing policy: " + partition); return producers.get(partition).internalSendAsync(message); }
/** * Choose a partition based on msg and the topic metadata. * * @param msg message to route * @param metadata topic metadata * @return the partition to route the message. * @since 1.22.0 */ default int choosePartition(Message<?> msg, TopicMetadata metadata) { return choosePartition(msg); }
@Override CompletableFuture<MessageId> internalSendAsync(Message<T> message) { switch (getState()) { case Ready: case Connecting: break; // Ok case Closing: case Closed: return FutureUtil.failedFuture(new PulsarClientException.AlreadyClosedException("Producer already closed")); case Terminated: return FutureUtil.failedFuture(new PulsarClientException.TopicTerminatedException("Topic was terminated")); case Failed: case Uninitialized: return FutureUtil.failedFuture(new PulsarClientException.NotConnectedException()); } int partition = routerPolicy.choosePartition(message, topicMetadata); checkArgument(partition >= 0 && partition < topicMetadata.numPartitions(), "Illegal partition index chosen by the message routing policy: " + partition); return producers.get(partition).internalSendAsync(message); }