1
votes

I have three queues and one worker that I want monitoring the three queues (or only two of them)

One queue is qPirate One queue is qShips One queue is qPassengers

The idea is that workers will either be looking at all 3 of them, 2 of them, or one of them, and doing different things depending on what the message says.

The key though is that say a message is failing because ship1 is offline, all queues in qships will refresh, workers that are looking at that and other queues will get hung up slightly from it as they will try to process the messages for that queue while only looking at the other queues a little bit, while the other workers that are looking at the other 2 queues and skipping qships will continue to process through messages without holdup or delays.

    public static void GotMessage([ServiceBusTrigger("%LookAtAllQueuesintheservicebus%")] BrokeredMessage message)
    {
        var handler = new MessageHandler();

        var manager = new MessageManager(
            handler,
            "PirateShips"
            );

        manager.ProcessMessageViaHandler(message);
    }

Looking around online I'm guessing this isn't something that's possible, but it seems like it would be? Thanks in advance either way!

Edit1: I'll add the Job Host as well to attempt to clarify things a bit

        JobHostConfiguration config = new JobHostConfiguration()
        {
            DashboardConnectionString = "DefaultEndpointsProtocol=https;AccountName=PiratesAreUs;AccountKey=Yarr",
            StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=PiratesAreUs;AccountKey=Yarr",
            NameResolver = new QueueNameResolver()
        };

        ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration()
        {
            ConnectionString = "Endpoint=AllPirateQueuesLocatedHere;SharedAccessKeyName=PiratesAreUs;SharedAccessKey=Yarr"               
        };

        serviceBusConfig.MessageOptions.AutoComplete = false;
        serviceBusConfig.MessageOptions.AutoRenewTimeout = TimeSpan.FromMinutes(1);
        serviceBusConfig.MessageOptions.MaxConcurrentCalls = 1;            

        config.UseServiceBus(serviceBusConfig);


        JobHost host = new JobHost(config);

        host.RunAndBlock();

Also the QueueNameResolverClass is simply

    public class QueueNameResolver : INameResolver
    {
        public string Resolve(string name)
        {
            return name;
        }
    }

I don't appear to have anyway to have the NameResolver be multiple queues, while I can say that I want the jobhost to look at a certain ServiceBus, I don't know how to tell it to look at all the queues within the ServiceBus.

In other words, I want multiple servicebustriggers on this worker so that if a message gets sent to qpirate1 and qships1 which are both located in service bus AllPirateQueuesHere, the worker can pick up the message in qpirate1, process it, then pick up the message in qships1 and process it.

1
These messages are being consumed from Azure Webjobs?JTaub
Looking at the signature, yes John.Sean Feldman
@ivan-s, can you explain a little bit more please? I really have some difficulty to understand what you try to achieve... ThanksThomas
Added some more code and explanation. Hope it helps. Thanks in advance either way!Ivan S

1 Answers

1
votes

Figured out the answer... This is possible and its simpler than I thought I'm not sure why I didn't connect the dots but I'm still curious why there isn't more documentation about this. Apparently it's simply make a function per queue you want a worker to look at multiple queues. So if you had three queues you'd want something like the below (you can handle each message differently).

  public static void GotMessage1([ServiceBusTrigger("%qPirate1%")] BrokeredMessage message)
{
    var handler = new MessageHandler();

    var manager = new MessageManager(
        handler,
        "Pirates"
        );

    manager.ProcessMessageViaHandler(message);
}

  public static void GotMessage2([ServiceBusTrigger("%qShip1%")] BrokeredMessage message)
{
    var handler = new MessageHandler();

    var manager = new MessageManager(
        handler,
        "Ships"
        );

    manager.ProcessMessageViaHandler(message);
}

  public static void GotBooty([ServiceBusTrigger("%qBooty%")] BrokeredMessage message)
{
    var handler = new MessageHandler();

    var manager = new MessageManager(
        handler,
        "Booty"
        );

    manager.ProcessMessageViaHandler(message);
}