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

Event Hubs: Update EventProcessorClient component to pull BlobClient from DI #3293

Merged
merged 11 commits into from
Apr 12, 2024

Conversation

oising
Copy link
Contributor

@oising oising commented Mar 30, 2024

  • Update AzureComponent to pass concrete AzureClientFactoryBuilder and remove TBuilder generic
  • Update associated components (RegisterClientFactory is replaced with concrete AddClient call)
  • Update launchSettings.json in EH sample AppHost
  • Update EventProcessorClient component to pull BlobServiceClient from DI

The BlobServiceClient is first looked for as a keyed service using settings.BlobConnectionName -- the serviceKey is always the same as the connectionName for keyed services. If this is not found, a default service is looked for. If this is not found, an InvalidOperationException is thrown with a helpful message. This is a breaking change from Preview 5.

Closes #3254

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 30, 2024
@oising oising marked this pull request as draft March 30, 2024 03:29
@oising oising marked this pull request as ready for review March 30, 2024 04:36
@oising
Copy link
Contributor Author

oising commented Mar 30, 2024

fyi @eerhardt

@sebastienros sebastienros self-requested a review April 11, 2024 19:10
@@ -114,7 +116,7 @@ private sealed class TableServiceComponent : AzureComponent<AzureDataTablesSetti
return !string.IsNullOrEmpty(connectionString) ? new TableServiceClient(connectionString, options) :
cred is not null ? new TableServiceClient(settings.ServiceUri, cred, options) :
new TableServiceClient(settings.ServiceUri, options);
}, requiresCredential: false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the impact of changing this? I see that it's always true in AddClient methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be changing this. We need to keep the current behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed most changes back to the way they were. I missed the EventHubs ones, but I need to step away. Can you take care of that? I can take care of it when I get back too.

settings.ConsumerGroup ?? EventHubConsumerClient.DefaultConsumerGroupName, settings.Namespace,
settings.EventHubName, cred, options);

return processor;

}, requiresCredential: false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no available method that provides options, cred, provider and requiresCredential. The ultimate private call has these but there is no public combination that allows to access it. Ideally on AddClient since this is the one we wanted. I assume the expectation was that if you provide a factory with TokenCredential you'd want requiresCredential: true but here we don't always.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to successfully use this using a connection string. So I'm not sure we need to specify requiresCredential: false. Since this is a new component, we shouldn't be breaking anyone. But let's keep the other components doing what they are doing now. This one can use AddClient.

@tg-msft - do you know what this requiresCredential bool does/means exactly? Why can't I specify requiresCredential: false when I use the overloads with IServiceProvider?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is the problem I had -- there was no public overload available that allowed specifying it when you want the service provider. I couldn't immediately see what the point of this flag even was, so I figured it was vestigial as everything seemed to work regardless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requiresCredential is a niche feature for services that allow anonymous auth (i.e., reads on a Storage account used for hosting static websites). I believe it only controls whether or not we throw an exception when resolving a client if there was no credential provided. https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/extensions/Microsoft.Extensions.Azure/src/Internal/ClientRegistration.cs#L46

Remove the need to specify a BlobClientServiceKey, and use an unkeyed client if none is provided.
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I pushed a few minor changes.

Thanks for the great contributions @oising!

@eerhardt eerhardt merged commit 56da7a4 into dotnet:main Apr 12, 2024
8 checks passed
@oising oising deleted the eventhubprocessor-blobclient-di branch April 13, 2024 14:52
eerhardt added a commit to eerhardt/aspire that referenced this pull request Apr 24, 2024
…from DI (dotnet#3293)

* update sample EH project launchsettings; add blob component for processor

* update azurecomponent to expose serviceprovider; update associated components; update processor for DI retrieval of blob client

* throw if blobclient cannot be retrieved from DI (this is a breaking change from P5)

* fix tests

* PR feedback

* More PR feedback

* Rename BlobClientConnectionName to BlobClientServiceKey.

Remove the need to specify a BlobClientServiceKey, and use an unkeyed client if none is provided.

* fix tests

* fixup formatting

---------

Co-authored-by: Eric Erhardt <[email protected]>
Co-authored-by: Sebastien Ros <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EventProcessorClient should use DI for blob client (Event Hubs)
5 participants