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

<p>I understand better now, Here is the <a href="https://images.squarespace-cdn.com/content/v1/56894e581c1210fead06f878/1532295877340-V08C7VRC02TR94J303GM/ke17ZwdGBToddI8pDm48kJMyHperWZxre3bsQoFNoPhZw-zPPgdn4jUwVcJE1ZvWEtT5uBSRWt4vQZAgTJucoTqqXjS3CfNDSuuf31e0tVGDclntk9GVn4cF1XFdv7wlNvED_LyEM5kIdmOo2jMRZpu3E9Ef3XsXP1C_826c-iU/KafkaPubSub.png?format=500w" rel="nofollow noreferrer">Image Link</a> i posted earlier. I'm sure you already know about it. It is a common issue and the best way is to use a redis acting as a "<a href="https://redis.io/commands/brpop" rel="nofollow noreferrer">blocking</a>" mechanism. Since the message queue is sending requests asynchronously to all the consumers, we will not know who is receiving and processing the request but we are ensure that it isn't processed by all by using blocking. Before doing any operation, check for the block and if it doesn't exist, process the request. </p>
