Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a way to pass Name of Factory Client to Function Triggers #43650

Open
jonmeyerson opened this issue Apr 25, 2024 · 1 comment
Open

Expose a way to pass Name of Factory Client to Function Triggers #43650

jonmeyerson opened this issue Apr 25, 2024 · 1 comment
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus

Comments

@jonmeyerson
Copy link

jonmeyerson commented Apr 25, 2024

Library name

Microsoft.Azure.Functions.Worker

Please describe the feature.

Feature Request:

Currently when using a ServiceBusTrigger you need to specify the Connection String - It would be nice if we could instead pass the name of a Factory Client and it would be able to proceed from there. This internally could rely on the IAzureClientFactory for DI.
This could also be extended to other clients that have connections like BlobTrigger/QueueTrigger

services.AddAzureClients((factoryBuilder) =>
{
    factoryBuilder
        .AddClient<ServiceBusClient, ServiceBusClientOptions>((options, serviceProvider) =>
        {
            string Connectionstring = //custom logic. 
            return new ServiceBusClient(Connectionstring, options);
        })
        .WithName("ServiceBusClientName");
    factoryBuilder
         .AddClient<ServiceBusReceiver, ServiceBusReceiverOptions>((options, serviceProvider) =>
         {
             var factory = serviceProvider.GetRequiredService<IAzureClientFactory<ServiceBusClient>>();
             var client = factory.CreateClient("ServiceBusClientName");
             return client.CreateReceiver("QueueName", options);
          }).WithName(ServiceBusReceiverClientName);
});
public string ServiceBusReceivedMessageFunction(
      [ServiceBusTrigger(ClientName = "ServiceBusReceiverClientName")] ServiceBusReceivedMessage message)
{
      var outputMessage = $"Output message created at {DateTime.Now}";
      return outputMessage;
}

Problem being solved:
Able to use DI to setup the Connection AND options.

And in the future something like this could be registered and tied to a new Trigger [ServiceBusTrigger(ClientName = "ServiceBusSession1", IsSessionsEnabled = true)]

factoryBuilder.AddClient<ServiceBusSessionProcessor, ServiceBusSessionProcessorOptions>((options, serviceProvider) =>
{
    var factory = serviceProvider.GetRequiredService<IAzureClientFactory<ServiceBusClient>>();
    var _options = serviceProvider.GetRequiredService<IOptions<MyOptions>>();
    var client = factory.CreateClient(MyOptions.ClientName);
    options = new ServiceBusSessionProcessorOptions
    {
        MaxConcurrentSessions = _options.Value.MaxConcurrentSessions,
        MaxConcurrentCallsPerSession = 1,//Guarantees order.
        ReceiveMode = ServiceBusReceiveMode.ReceiveAndDelete,
        PrefetchCount = _options.Value.PrefetchCount,
        MaxAutoLockRenewalDuration = _options.Value.SessionTimeToLive //Prevent session starvation.
    };
    return client.CreateSessionProcessor(_options.Value.TopicName, _options.Value.SubscriptionName, options);
}).WithName("ServiceBusSession1");

Currently options for servicebustrigger are only configurable in host.json, this would allow them to pull from here.

Edit:
It looks the the ServiceBusListener used by the current ServiceBusTrigger is using MessagingProvider as a factory, instead of registering them to the IAzureClientFactory<> and retrieving them from there. There is also a separate class ServiceBusClientFactory also using MessagingProvider. currently it is using a concurrent dictionary with a key generated by entityPath which is generated by the code based on inputs.

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus labels Apr 25, 2024
Copy link

Thank you for your feedback. Tagging and routing to the team member best able to assist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Projects
None yet
Development

No branches or pull requests

2 participants