Search code examples
apache-pulsarpulsar

Is it possible to have multiple producers for the same topic on Pulsar?


I know you can set topic subscription to be shared subscription to allow for multiple Consumers on the same topic. Can this also be done for multiple Producers?

For some reason when I try to, I get a Producer with name '<topic_name>' is already connected to topic


Solution

  • Yes, you can have multiple producers on a topic. You just have to make sure each producer has a unique name. From the ProducerBuilder.producerName section of the Java client API docs:

    When specifying a name, it is up to the user to ensure that, for a given topic, the producer name is unique across all Pulsar's clusters. Brokers will enforce that only a single producer a given name can be publishing on a topic.

    The easiest way to ensure the producer name is unique is to let Pulsar set it automatically for you. From the same section:

    If not assigned, the system will generate a globally unique name which can be accessed with Producer.getProducerName().