Conversation
Enhance ChannelMediator.AzureBus to support dynamic topic discovery and immediate subscription refresh. - Publisher sends a reload signal to a special reload-topics topic when creating new topics. - Reader service listens for reload signals and subscribes to new topics without restart. - Entity manager handles concurrent topic/queue/subscription creation. - Sample updated to publish multiple notifications and demonstrate new OrderShippedNotification/handler. - Bump package version to 1.1.13.0.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances ChannelMediator.AzureBus to support dynamic topic discovery and an immediate subscription refresh mechanism via an internal reload-topics topic, so reader services can start consuming newly created notification topics without a restart.
Changes:
- Added a publisher-side one-time topic setup that creates topics/subscriptions and emits a reload signal when a new topic is created.
- Added a reader-side reload processor + refresh logic to discover topics at runtime and start new
TopicSubscriptionReaderinstances. - Updated samples to publish/handle a new
OrderShippedNotification, and bumped the AzureBus package version.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Samples/ChannelMediatorSampleShared/OrderShippedNotification.cs | Adds a new shared notification contract for sample messaging. |
| src/Samples/AzureBusWriterSampleConsole/Program.cs | Publishes multiple notifications (including OrderShippedNotification) to demonstrate dynamic topic behavior. |
| src/Samples/AzureBusReaderSampleConsole/Program.cs | Forces Development environment for sample configuration consistency. |
| src/Samples/AzureBusReaderSampleConsole/OrderShippedHandler.cs | Adds a sample notification handler for OrderShippedNotification. |
| src/ChannelMediator.AzureBus/TopicSubscriptionReadersHostedService.cs | Implements reload-signal processor + dynamic topic refresh/subscription. |
| src/ChannelMediator.AzureBus/TopicSubscriptionReader.cs | Adjusts publish dispatch to use runtime notification type. |
| src/ChannelMediator.AzureBus/ChannelMediator.AzureBus.csproj | Bumps package version to 1.1.13.0. |
| src/ChannelMediator.AzureBus/AzureServiceBusPublisher.cs | Adds concurrent-safe topic initialization + reload signal emission. |
| src/ChannelMediator.AzureBus/AzureServiceBusNameBuilder.cs | Adds helper to build the internal reload topic name. |
| src/ChannelMediator.AzureBus/AzureServiceBusEntityManager.cs | Adds concurrent-create handling and returns “created” flag for topics. |
Comment on lines
+70
to
+74
| var isNewTopic = await _entityManager.EnsureTopicExistsAsync(topicName); | ||
| if (!isNewTopic) | ||
| { | ||
| return; | ||
| } |
Comment on lines
+51
to
56
| var lazySetup = _topicSetupTasks.GetOrAdd( | ||
| queueOrTopicName, | ||
| name => new Lazy<Task>(() => SetupTopicAsync(name, typeof(TNotification)))); | ||
|
|
||
| await lazySetup.Value; | ||
|
|
Comment on lines
+76
to
+83
| await _entityManager.EnsureSubscriptionExistsAsync( | ||
| topicName, | ||
| _options.TopicSubscriberName, | ||
| notificationType); | ||
|
|
||
| await SendReloadSignalAsync(topicName, CancellationToken.None); | ||
| } | ||
|
|
| } | ||
| catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists) | ||
| { | ||
| _logger.LogTrace("Topic '{TopicName}' was created concurrently by another process.", topicName); |
Comment on lines
167
to
169
| _logger.LogTrace("Publishing notification of type {NotificationType} from topic {Topic}/{Subscription}.", notification.GetType().FullName, _options.TopicName, _options.SubscriptionName); | ||
| await mediator.Publish((INotification)notification, cancellationToken); | ||
| await mediator.Publish((dynamic)notification, cancellationToken); | ||
| } |
Comment on lines
+80
to
+86
| var reloadTopicName = AzureServiceBusNameBuilder.BuildReloadTopicName(options.Prefix); | ||
| var subscriptionName = options.TopicSubscriberName.ToLowerInvariant(); | ||
|
|
||
| await entityManager.EnsureTopicExistsAsync(reloadTopicName, cancellationToken); | ||
| await entityManager.EnsureSubscriptionExistsAsync(reloadTopicName, subscriptionName, typeof(INotification), cancellationToken); | ||
|
|
||
| _logger.LogInformation("[reload-topics] Listening on internal topic '{ReloadTopic}' / subscription '{Subscription}'.", reloadTopicName, subscriptionName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhance ChannelMediator.AzureBus to support dynamic topic discovery and immediate subscription refresh.