yanis
yanis

Reputation: 333

Azure function binding multiple Service Bus events

Is there a way to make an Azure function triggerable by multiple Service Bus event queues? For example, if there is a function which logic is valid for multiple cases(event start, event end- each inserted into a different Service Bus queue) and I want to reuse it for these events can I subscribe to both of them in the Service Bus from the same function?

I was looking for an answer to this question, but so far everywhere I checked it seems to be impossible.

Upvotes: 4

Views: 6910

Answers (3)

Simon Luckenuik
Simon Luckenuik

Reputation: 355

If your goal is to simply reuse code, what about refactoring that Function to create a class which is then used in multiple functions.

If your goal is implementing events aggregation, you could probably create an Azure Durable Function Workflow that would do a fan-in on multiple Events.

Excerpt from https://github.com/Azure/azure-functions-durable-extension/issues/166:

Processing Azure blobs in hourly batches.

  1. New blob notifications are sent to a trigger function using Event Grid trigger.

  2. The event grid trigger uses the singleton pattern to create a single orchestration instance of a well-known name and raises an event to the instance containing the blob payload(s).

  3. To protect against race conditions in instance creation, the event grid trigger is configured as a singleton using SingletonAttribute.

  4. Blob payloads are aggregated into a List and sent to another function for processing - in this case, aggregated into a single per-batch output blob.

  5. A Durable Timer is used to determine the one-hour time boundaries.

Upvotes: 2

DTRT
DTRT

Reputation: 11040

You might want to consider switching the pattern around by using only one queue but multiple Topics/Subscriptions for the clients.

Then the Function in question can be triggered by the Start-End Topic.

Some other Function can be triggered by the Working Topic, etc.

Upvotes: 0

Sean Feldman
Sean Feldman

Reputation: 25994

Azure Functions can be triggered by a single source queue or subscription. If you'd like to consolidate multiple sources to serve as a trigger for a single function, you could forward messages to a single entity (let's assume a queue) and configure Function to be triggered by messages in that queue. Azure Service Bus support Auto-Forwarding natively.

Note that there cannot be more than 3 hops and you cannot necessarily know what the source was if message was forwarded from a queue. For subscriptions, there's a possible workaround to stamp messages.

Upvotes: 5

Related Questions