title: Is it correct to encapsulate KafkaTemplate/handling methods in your own wrapper(and how)?
body: <p>I try to introduce <strong>apache Kafka</strong> to our project and change projects architecture to <strong>producer-consumer</strong>. I experiment on a new test project. For example, I have one producer and two consumers. It is different spring-boot applications(microservices). </p>
  
  <p>In producer service, I need to configure Kafka, create <code>KafkaTemplate</code>. In each consumer, I need to configure Kafka and create handlers(methods with <code>@KafkaListener</code> annotation).</p>
  
  <p>For example, tomorrow we will want to change Kafka to something another, we will change <code>KafkaTemplate</code> and methods with <code>@KafkaListener</code> annotation to an implementation of a new library. This is not a good approach. So I consider that we need to create our wrapper. Something like this:</p>
  
  <pre><code>public interface EventBus {
      void sendMessage(String topicName, String message);
  }
  </code></pre>
  
  <p>And encapsulate KafkaTemplate in the implementation of this interface(<code>KafkaEventBus implements EventBus</code>)</p>
  
  <p>I start to implement it but I faced the fact that I do not understand how to do it. I create a Gradle module with 'event-bus' name. This module is not spring - just java module. I create <code>EventBus</code> interface and implement it:</p>
  
  <pre><code>public class KafkaEventBus implements EventBus {
  
      private final KafkaProducer&lt;String, String&gt; kafkaProducer;
  
      public KafkaEventBus() {
          this.kafkaProducer = new KafkaProducer&lt;&gt;(producerConfig());
      }
  
      @Override
      public void sendMessage(String topicName, String message) {
          kafkaProducer.send(new ProducerRecord&lt;&gt;(topicName,message));
      }
  
      private Map&lt;String, Object&gt; producerConfig() {
          Map&lt;String, Object&gt; configProps = new HashMap&lt;&gt;();
          configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
          configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
          configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
          return configProps;
      }
  }
  </code></pre>
  
  <p>And stuck. I have questions:</p>
  
  <p>1) Do I need to create a different module(event-bus)? Do I think right?</p>
  
  <p>2) How can implement message handling in this module? If sending something is clear(encapsulate <code>KafkaTemplate</code> and delegate message to it) then with handling 
  ничего не понятно
  nothing is clear.</p>
  
  <p>Maybe, Are there some examples of this, best practices? </p>