title: Asynchronous Message-Passing and Microservices
body: <p>I am planning the develop of a microservice based architecture application and I decided to use kafka for the internal communicaton while I was reading the book <em>Microservice Architecture by Ronnie Mitra; Matt McLarty; Mike Amundsen; Irakli Nadareishvili</em> where they said: </p>
  
  <blockquote>
    <p>letting microservices directly interact with message brokers (such as
    RabbitMQ, etc.) is rarely a good idea. If two microservices are
    directly communicating via a message-queue channel, they are sharing a
    data space (the channel) and we have already talked, at length, about
    the evils of two microservices sharing a data space. Instead, what we
    can do is encapsulate message-passing behind an independent
    microservice that can provide message-passing capability, in a loosely
    coupled way, to all interested microservices.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/XK10H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XK10H.png" alt="enter image description here"></a></p>
  
  <p>I am using Netflix Eureka for Service registration and discovery, Zuul as edge server and Hystrix. 
  Said so, in practice, how can I implement that kind of microservice? How can I make my microservices indipendent from the communcation channel ( in this case Kafka)? 
  Actually I'm directly interacting with the channel, so I don't have an extra layer between my publishers/subscribers and kafka.</p>
  
  <p><strong>UPDATE 06/02/2018</strong></p>
  
  <p>to be more precise, we have a couple of microservices: one is publishing news on a topic (activemq, kafka...) and the other microservice is subscribed on that topic and doing some operations on the messages that are coming through. So we have these services that are coupled to the message broker (to the channel)... we have the the message broker's apis "embedeed" on our code and for example, if we want to change the message broker we have to change all the microservices that made use of the message broker's api. So, they are suggesting to use a microservice(in the picture I assume is the Events Hub) that is the "dispatcher" of the various messages. In this way it is the only component that interacts with the channel.</p>