Home > Enterprise >  Reusing ServiceBusReceivers for ServiceBusTriggers
Reusing ServiceBusReceivers for ServiceBusTriggers

Time:02-22

Following the best practices for reuse of Service Bus factories and clients, the reuse of ServiceBusReceiver is recommended. This great answer for another question shows how a factory with such receivers can be implemented, which is then meant to be used as a singleton. However, I can't seem to find details of how this can be used together with a ServiceBusTrigger. Can this be done?

I guess my question stems from a limited understanding of how the ServiceBusTrigger is actually triggered, and how the different parameters of a trigger can be bound. I.e. does the trigger somehow create and use ServiceBusReceiver under the hood? Any additional insight into this area is greatly appreciated!

Using the in-process worker for .Net 6, for a project with multiple ServiceBusTriggers

CodePudding user response:

The trigger creates and manages the ServiceBusClient and any senders/receivers that are used. Since the trigger is already handing messages to your function, normally, you wouldn't need to bind to the receiver directly for use in the body of the function; for message settlement and related activities, you'd make use of the ServiceBusMessageActions as demonstrated here.

I don't believe that it is currently possible to bind directly to a ServiceBusReceiver via the trigger; it appears we redirect that to the message actions implicitly (src) - but I haven't tried to verify that.

  • Related