vendredi 8 janvier 2021

How to route message to right queue when working with multiple regional Azure Queues

I have an app which is distributed to five regions, US, EU, China, etc.

Requests are routed to the closest worker to the client, however some aspects of the requests must be processed in the specific regions according to some business logic, like if the client is for instance requesting info from the NYSE but are in Europe, most of the work could happen in Europe but some of the work has to happen in the US region.

When that happens I use the right QueueClient for the right region to send a message over there where that sensitive work is processed.

I have a routing client to determine when we need to send those messages to the right region, which works fine. However I find I need to manage multiple queue clients.

Looking for a design pattern that handles this need, because today I'm doing this:

public class MyService : IMyAppService
    {
        private readonly IMyAppQueueEventClient usQueueClient;
        private readonly IMyAppQueueEventClient euQueueClient;
        private readonly IMyAppQueueEventClient cnQueueClient;

        public MyAppService(IMyAppQueueEventClient USQueueClient, 
            IMyAppQueueEventClient EUqueueClient;
            IMyAppQueueEventClient CNqueueClient;
            )
        {
            
            this.usQueueClient = USQueueClient;
            this.euQueueClient = EUQueueClient;
            this.cnQueueClient = CNQueueClient;
            
        }

This feels really clunky. As I add new regions I end up having to update the constructer, which leads to follow on changes to update the tests, etc etc.

Surely there is a way to just read from appSettings and make an array of QueueClients and pass them in, and then just pick the right one.

Aucun commentaire:

Enregistrer un commentaire