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
Hi, thanks for the package. Could you please give us an example webjob which use your extension, how to put the RabbitMQ connection settings?
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();
}
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,
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
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
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.
Thank you, do let me know if there is anything I can help with or improve.
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
Thank you for sharing your efforts. If I have Azure App Service free subscription, can I install Rabbitmq over there and how?
Hi, is it possible to listen to more than 1 queue which can be set up or pass through RabbitQueueTrigger? cheers
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
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?