<p>I am trying to have several different Spring Cloud Microservices all connect to a Kafka/Zookeeper Cluster, all within Kubernetes. The Microservices are using <code>org.springframework.kafka:spring-kafka</code> - as both consumers and producers of events.</p>
<p>All of the services connect to kafka okay - and topics are created; however the consumers of each service are very inconsistent.</p>
<p>For example, when the services start one time, all of the consumers will listen for the message and the function is invoked. But then, when I restart everything (kafka and zookeeper included), it will either just not work, or some of the consumers in different services will work etc...</p>
<p>Here is some of my config - I don't have any Java-based config - just in my application.yml as follows:</p>
<pre><code>spring:

  ....

  kafka:
    consumer:
      bootstrap-servers: api-kafka.default.svc.cluster.local:9092
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      group-id: api-event
      enable-auto-commit: false

    producer:
      bootstrap-servers: api-kafka.default.svc.cluster.local:9092
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
      ack-mode: manual

...

</code></pre>
<p>And my main class:</p>
<pre><code>@EnableCaching
@SpringBootApplication
@EnableJpaRepositories
@EnableDiscoveryClient
@EnableKafka /* &lt;&lt;&lt;&lt;&lt;&lt;&lt;------------- ENABLED HERE */
public class ExampleServiceApplication {

  public static void main(String[] args) {
    SpringApplication.run(ExampleServiceApplication.class, args);
  }

  .....
}

</code></pre>
<p>And finally, my consumer:</p>
<pre><code>@Component
public class MessageListener {

  @KafkaListener(
      topics = &quot;myTopic&quot;)
  public void eventListener(String serializedMessage) {
    try {
....
</code></pre>
<p>The messages are getting sent to the broker fine, but just aren't consumed by the other services.</p>
<p>I realize that there is no mapping to the topics on each of the service properties, how do I do this via application.yml?</p>
<p>I bet I'm making a really nooby mistake but yeah! I'd really appreciate any comments or help</p>

Ben Neighbour
<p>Btw, you can read here more about the relation between the number of partitions and the number of parallel consumers (consumers with the same group id).</p>
<p><a href="https://docs.confluent.io/platform/current/streams/architecture.html" rel="nofollow noreferrer">https://docs.confluent.io/platform/current/streams/architecture.html</a></p>
<blockquote>
<p>Slightly simplified, the maximum parallelism at which your application may run is bounded by the maximum number of stream tasks, which itself is determined by maximum number of partitions of the input topic(s) the application is reading from. For example, if your input topic has 5 partitions, then you can run up to 5 applications instances. These instances will collaboratively process the topic’s data. If you run a larger number of app instances than partitions of the input topic, the “excess” app instances will launch but remain idle; however, if one of the busy instances goes down, one of the idle instances will resume the former’s work. We provide a more detailed explanation and example in the FAQ.</p>
</blockquote>
