我的Golang应用程序中需要一个或多个sarama.SyncProducer吗?

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:

  1. How many sarama.SyncProducer do I need?
  2. Is it fine to use one across all app? Shall I have some kind of producer pool?

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:

  1. I'd go with one, without knowing your requirements.
  2. Yes. I'd imagine it's more likely that one needs a pool of consumers, given of course, there's high rate of messages being published.
  1. 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

  2. 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.

  1. How many sarama.SyncProducer do I need?

You need only one producer struct with initialized configurations to set to multiple brokers.

  1. Is it fine to use one across all app? Shall I have some kind of producer pool ?

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.