title: Publishing an Event to a Single Microservice Instance
body: <p>I'm working on a project that has several event-driven microservices and also using Kubernetes for load balancing. All the services are both publishers and listeners. When a microservice publishes an event, all the listeners are catching the event (if it listens that specific event) and doing their job. There was no problem with this flow until this:</p>
  
  <p>Let's say I have a microservice responsible for sending e-mails. And this service is duplicated 2 times by the load balancer due to high load. Now we have 3 instances of e-mail service. When a "sendMail" event is published, all the 3 instances are catching the event and sending an e-mail for their own. At the end of the day 3 e-mail are being sent.</p>
  
  <p>My question is, can I configure a cloud bus that allows me to publish events for both scenarios. I want to say to an event "when a single listener catches you, disappear" or "go to every listener waiting out there".</p>
  
  <p>For example;</p>
  
  <p>Microservices: A, B, C</p>
  
  <p>Duplicated by load balancer: A1, A2, A3, B1...</p>
  
  <p>Case 1: I want to publish an event for all the services' instances.</p>
  
  <p>Case 2: I want to publish an event for service A instances.</p>
  
  <p>Case 3: I want to publish an event for a single instance of A (don't 
  care which).</p>
  
  <p>I have tried;
  Giving destinations to events, but all the instances have same bus name since they are duplicated as same. If I give/know a single instance bus name, I wouldn't use it because that pod might die.</p>
  
  <p>Event publishing;</p>
  
  <pre class="lang-java prettyprint-override"><code>applicationContext().publishEvent(
          new customEvent(
                  this,  // Source
                  busProperties().getId(),  // Origin Service
                  null  // Destination Service (null: all)
          )
  );
  </code></pre>
  
  <p>Event listener;</p>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class Listener implements ApplicationListener&lt;CustomEvent&gt; {
      @Override
      public void onApplicationEvent(CustomEvent event) {
          Foo();
      }
  }
  </code></pre>