Skip to content

Dynamic topic discovery & reload signal for AzureBus - #37

Merged
chouteau merged 1 commit into
mainfrom
marc/dev
May 19, 2026
Merged

chouteau merged 1 commit into
mainfrom
marc/dev

Conversation

@chouteau

Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI review requested due to automatic review settings May 19, 2026 20:23
@chouteau
chouteau merged commit 1291e2a into main May 19, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 TopicSubscriptionReader instances.
  • 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants