Skip to content

Commit 4399d6a

Browse files
committed
Remove "Default" rule when the class is Instantiated
1 parent e454940 commit 4399d6a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public EventBusServiceBus(IServiceBusPersisterConnection serviceBusPersisterConn
3030
_subscriptionClient = new SubscriptionClient(serviceBusPersisterConnection.ServiceBusConnectionStringBuilder,
3131
subscriptionClientName);
3232

33-
CreateConsumerChannel();
33+
RemoveDefaultRule();
34+
RegisterSubscriptionClientMessageHandler();
3435
}
3536

3637
public void Publish(IntegrationEvent @event)
@@ -60,7 +61,7 @@ public void Subscribe<T, TH>(Func<TH> handler)
6061
var eventName = typeof(T).Name;
6162
var containsKey = _subsManager.HasSubscriptionsForEvent<T>();
6263
if (!containsKey)
63-
{
64+
{
6465
try
6566
{
6667
_subscriptionClient.AddRuleAsync(new RuleDescription
@@ -104,7 +105,7 @@ public void Dispose()
104105
_subsManager.Clear();
105106
}
106107

107-
private void CreateConsumerChannel()
108+
private void RegisterSubscriptionClientMessageHandler()
108109
{
109110
_subscriptionClient.RegisterMessageHandler(
110111
async (message, token) =>
@@ -132,5 +133,20 @@ private async Task ProcessEvent(string eventName, string message)
132133
}
133134
}
134135
}
136+
137+
private void RemoveDefaultRule()
138+
{
139+
try
140+
{
141+
_subscriptionClient
142+
.RemoveRuleAsync(SubscriptionClient.DefaultRule)
143+
.GetAwaiter()
144+
.GetResult();
145+
}
146+
catch (MessagingEntityNotFoundException)
147+
{
148+
_logger.LogInformation($"The messaging entity {SubscriptionClient.DefaultRule} Could not be found.");
149+
}
150+
}
135151
}
136152
}

0 commit comments

Comments
 (0)