I am new in Golang, I need to write the app that will publish events to kafka, I can't find the answers on the following questions:
Unless you get the data to be published on a much higher rate than the publisher can publish it (?), given the sarama publisher is asynchronous and concurrent , I'd say you don't need more than one publisher. So to answer straight your questions:
It depends on how your app works. In most of the case, one producer is enough. It can interact with many topics... I let you read the example
Yes, that's very good. You can see the producer as the exit door of your application.
But, you should use an asynchronous producer. Sarama is asynchronous if I am not wrong.
SyncProducer
or AsyncProducer
return a producer struct with connection to broker defined in sarama.Config.
You need only one producer struct with initialized configurations to set to multiple brokers.
There is nothing like one producer can be used across all app. The only thing is it you can connect to same broker using the same configurations. Because if there is a different app you need to create a new producer with similar configurations.