Azure WebJobs and RabbitMQ

As I am working on a project that leverages RabbitMQ and Azure WebJobs. I needed to write webjob functions that are triggered by a message on a queue in RabbitMQ.

While searching around, I have not found an extension that integrates with Azure WebJobs in a nice way and that is how WebJobs.Extensions.RabbitMQ was born.

The library exposes 3 attributes.

RabbitQueueTriggerAttribute: this attribute will subscribe to the queue and triggers whenever a message arrives.
[RabbitQueueTrigger("queueName")]

RabbitQueueBinderAttribute: this attribute extends RabbitQueueTriggerAttribute to allow for dynamic creation of the queue and bind it to the exchange.
[RabbitQueueBinder("exchangeName", "routingKey", "errorExchangeName(optional)","autoDelete=false(optional)","durable=true(optional)","exclusive=false(optional)")]

RabbitMessageAttribute: this attribute allows you to publish a message to an exchange.
[RabbitMessage("exchangeName","routingKey","mandatory=false(optional)"]

 

Example of subscription example:

public void IntegrateApprovedProductToMarketPlace(
[RabbitQueueBinder("product", "product.approved", "error")]
[RabbitQueueTrigger("integration-product-approved")]
ProductApproved message, TextWriter log)
{
[handle message here]
}

Example of a publisher:

public void ProcessBulkOrders([some trigger],
[RabbitMessage("order","order.processed")]
out OrderProcessed message, TextWriter log)
{
[assign message value here]
}

The code is available on GitHub and Nuget

 

 

12 Responses to Azure WebJobs and RabbitMQ

  1. Jeff May 13, 2017 at 1:40 am #

    Hi, thanks for the package. Could you please give us an example webjob which use your extension, how to put the RabbitMQ connection settings?

    • Sarmaad May 26, 2017 at 12:05 am #

      Hi Jeff,

      You pass the configuration when you configure JobHostConfiguration:

      static void Main()
      {

      var config = new JobHostConfiguration();

      if (config.IsDevelopment)
      {
      config.UseDevelopmentSettings();
      }

      config.UseRabbitMq(ConfigurationManager.AppSettings[“RabbitMq/Endpoint”]);

      var host = new JobHost(config);
      host.RunAndBlock();
      }

      • Jeff May 26, 2017 at 12:27 pm #

        Thanks, Sarmaad. We using security connection with certificate files, do you have an example to show us how to set these setting to connect to the RabbitMQ?

        Thanks,

        • Sarmaad May 26, 2017 at 12:55 pm #

          you can easily fork the code from github and extend the RabbitMqExtensionConfig class to pass your certificate details.

          under the hood, i am using RabbitMQ.Client and this is their documentation on how to do that with example https://www.rabbitmq.com/ssl.html#configuring-dotnet

          if you then like me to include it in nuget, just give me a pull request and I can publish a new version of the package

  2. Ram Ramakrishnan May 25, 2017 at 4:54 am #

    Hello Sarmad – Thank you very much for creating this extension. I am currently trying to get this extension to work with our RabbitMQ set up. When the job host starts up, it does not seem to detect or find the RabbitMQ handler. I do call userabbitmq on start and I do see from the RabbitMQ management interface my client does create a connection to the queue server. It just seems to fail to register the subscriber. do you have any thoughts on this?

    Thanks
    Ram

    • Ram Ramakrishnan May 25, 2017 at 5:07 am #

      Please ignore my previous comment. I realized, I was not passing the proper JobHostConfiguration to the JobHost. And once again thank you for creating this extension, made my life easier.

      • Sarmaad May 26, 2017 at 12:06 am #

        Thank you, do let me know if there is anything I can help with or improve.

  3. Alex July 28, 2017 at 6:32 am #

    What about parallel processing, similar to Azure queue BatchSize ?

    https://docs.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-storage-queues-how-to#config

  4. Tarek January 13, 2018 at 11:22 pm #

    Thank you for sharing your efforts. If I have Azure App Service free subscription, can I install Rabbitmq over there and how?

  5. matt February 1, 2018 at 9:47 am #

    Hi, is it possible to listen to more than 1 queue which can be set up or pass through RabbitQueueTrigger? cheers

  6. MarkiE February 27, 2018 at 7:54 pm #

    Hi, Thanks for the package. It works fine with subscription though when I try to publish a message, I’m getting an error. Please check the following exception,
    https://imgur.com/TTTW7Ab

    public static void ProcessQueueMessage(
    [RabbitQueueBinder(
    exchange: “directexchange”,
    routingKey: “”,
    errorExchange: “”,
    autoDelete: false,
    durable: false,
    execlusive: false)]
    [RabbitQueueTrigger(“inqueue”)] string message,
    [RabbitMessage(“directexchange”, “outqueue”)] out string result, //output
    TextWriter log
    )

    When I remove –output queue, it works fine.

    Thank you

  7. Konstantin March 26, 2018 at 11:56 pm #

    Hi, this looks very useful, however I would like to use it for triggering Azure Functions methods. Is it actually possible to configure the RabbitMQ Uri from an Azure Function?

Leave a Reply to Ram Ramakrishnan Click here to cancel reply.