-
Notifications
You must be signed in to change notification settings - Fork 521
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
Allow specifying an Event Hub to use as the default EntityPath for namespace connection string #7105
base: main
Are you sure you want to change the base?
Allow specifying an Event Hub to use as the default EntityPath for namespace connection string #7105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -200,7 +200,9 @@ public static IResourceBuilder<AzureEventHubsResource> RunAsEmulator(this IResou | |||||
// an event hub namespace without an event hub? :) | ||||||
if (builder.Resource.Hubs is { Count: > 0 } && builder.Resource.Hubs[0] is { } hub) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
var healthCheckConnectionString = $"{connectionString};EntityPath={hub.Name};"; | ||||||
var healthCheckConnectionString = connectionString.Contains(";EntityPath=") ? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of Contains, we could parse it properly and build a new one. |
||||||
connectionString : $"{connectionString};EntityPath={hub.Name};"; | ||||||
|
||||||
client = new EventHubProducerClient(healthCheckConnectionString); | ||||||
} | ||||||
else | ||||||
|
@@ -365,7 +367,7 @@ public static IResourceBuilder<AzureEventHubsEmulatorResource> WithHostPort(this | |||||
/// <param name="path">Path to the file on the AppHost where the emulator configuration is located.</param> | ||||||
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||||||
public static IResourceBuilder<AzureEventHubsEmulatorResource> WithConfigurationFile(this IResourceBuilder<AzureEventHubsEmulatorResource> builder, string path) | ||||||
{ | ||||||
{ | ||||||
// Update the existing mount | ||||||
var configFileMount = builder.Resource.Annotations.OfType<ContainerMountAnnotation>().LastOrDefault(v => v.Target == AzureEventHubsEmulatorResource.EmulatorConfigJsonPath); | ||||||
if (configFileMount != null) | ||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -47,8 +47,29 @@ public class AzureEventHubsResource(string name, Action<AzureResourceInfrastruct | |||
/// </summary> | ||||
public ReferenceExpression ConnectionStringExpression => | ||||
IsEmulator | ||||
? ReferenceExpression.Create($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.Host)}:{EmulatorEndpoint.Property(EndpointProperty.Port)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;") | ||||
: ReferenceExpression.Create($"{EventHubsEndpoint}"); | ||||
? ReferenceExpression.Create($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.Host)}:{EmulatorEndpoint.Property(EndpointProperty.Port)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true{BuildEntityPath()}") | ||||
: ReferenceExpression.Create($"{EventHubsEndpoint}{BuildEntityPath()}"); | ||||
|
||||
private string BuildEntityPath() | ||||
{ | ||||
if (!Hubs.Any(hub => hub.IsDefaultEntity)) | ||||
{ | ||||
// Of zero or more hubs, none are flagged as default | ||||
return string.Empty; | ||||
} | ||||
|
||||
try | ||||
{ | ||||
// Of one or more hubs, only one may be flagged as default | ||||
var defaultEntity = Hubs.Single(hub => hub.IsDefaultEntity); | ||||
|
||||
return $";EntityPath={defaultEntity.Name}"; | ||||
} | ||||
catch (InvalidOperationException ex) | ||||
{ | ||||
throw new InvalidOperationException("Only one EventHub can be configured as the default entity.", ex); | ||||
} | ||||
} | ||||
Comment on lines
48
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
|
||||
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName) | ||||
{ | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: