<p>I have a microservice deployed in a container with 2 replicas. So I have 2 pods. This microservice receive commands from another service through the Azure Service Bus. My issue is that i want to retrieve the commands with one of the two pods. I've tryed to enable Sessions and use SessionId but I still receive commands in the wrong pod. Is there any way to make this? </p>

<p>Here i leave how do i configure the bus (using masstransit library)</p>

<pre><code>var bus = Bus.Factory.CreateUsingAzureServiceBus(sbc =&gt;
        {
            var host = sbc.Host(_configuration["myConnectionString"], h =&gt; { });
            sbc.ConfigureSend(x =&gt; x.UseExecute(context =&gt;
            {
                var sessionId = EnvConstants.SessionId;
                context.SetSessionId(sessionId);
            }));
            sbc.ReceiveEndpoint(host, _configuration["myQueueName"], e =&gt;
            {
                e.RequiresSession = true;
                e.Instance(consumer);
                e.UseContextFilter(c =&gt;
        {
               //I tryed this filter but sends my command to the skipped queue. 
            var sameSessionId = c.SessionId() == EnvConstants.SessionId;
            return Task.FromResult(sameSessionId);
        });
            });
        });
</code></pre>

Dani Alderete
<p>I don't believe its best practice to differentiate replicas in any way, as they are meant to be stateless with no specific identifier at the pod level, so you can't tell them apart in a guaranteed way.</p>

<p>For scenarios such as yours, you should opt for <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">Stateful Sets</a>, which provides an ordinal identifier to the pods that you can use to tell them apart (and guarantee it). And depending on the identifier, you could have special queues (or subscriptions to a single topic) to address a specific pod.</p>
