@@ -16,23 +16,20 @@ public class ServiceBusLifeCycleEventHub : ILifeCycleEventHub
1616 private readonly ITopicClient _topicClient ;
1717 private readonly ILogger _logger ;
1818 private readonly ISubscriptionClient _subscriptionClient ;
19- private readonly ICollection < Action < LifeCycleEvent > > _subscribers =
20- new HashSet < Action < LifeCycleEvent > > ( ) ;
21- private readonly JsonSerializerSettings _serializerSettings =
22- new JsonSerializerSettings
23- {
24- TypeNameHandling = TypeNameHandling . All ,
25- ReferenceLoopHandling = ReferenceLoopHandling . Error ,
26- } ;
19+ private readonly ICollection < Action < LifeCycleEvent > > _subscribers = new HashSet < Action < LifeCycleEvent > > ( ) ;
20+ private readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
21+ {
22+ TypeNameHandling = TypeNameHandling . All ,
23+ ReferenceLoopHandling = ReferenceLoopHandling . Error ,
24+ } ;
2725
2826 public ServiceBusLifeCycleEventHub (
2927 string connectionString ,
3028 string topicName ,
3129 string subscriptionName ,
3230 ILoggerFactory logFactory )
3331 {
34- _subscriptionClient = new SubscriptionClient (
35- connectionString , topicName , subscriptionName ) ;
32+ _subscriptionClient = new SubscriptionClient ( connectionString , topicName , subscriptionName ) ;
3633 _topicClient = new TopicClient ( connectionString , topicName ) ;
3734 _logger = logFactory . CreateLogger ( GetType ( ) ) ;
3835 }
@@ -55,14 +52,12 @@ public void Subscribe(Action<LifeCycleEvent> action)
5552
5653 public Task Start ( )
5754 {
58- var sessionHandlerOptions = new SessionHandlerOptions ( ExceptionHandler )
55+ var messageHandlerOptions = new MessageHandlerOptions ( ExceptionHandler )
5956 {
60- MaxConcurrentSessions = 1 ,
6157 AutoComplete = false
6258 } ;
6359
64- _subscriptionClient . RegisterSessionHandler (
65- MessageHandler , sessionHandlerOptions ) ;
60+ _subscriptionClient . RegisterMessageHandler ( MessageHandler , messageHandlerOptions ) ;
6661
6762 return Task . CompletedTask ;
6863 }
@@ -73,10 +68,7 @@ public async Task Stop()
7368 await _subscriptionClient . CloseAsync ( ) ;
7469 }
7570
76- private async Task MessageHandler (
77- IMessageSession messageSession ,
78- Message message ,
79- CancellationToken cancellationToken )
71+ private async Task MessageHandler ( Message message , CancellationToken cancellationToken )
8072 {
8173 try
8274 {
@@ -92,15 +84,13 @@ await _subscriptionClient
9284 }
9385 catch
9486 {
95- await _subscriptionClient
96- . AbandonAsync ( message . SystemProperties . LockToken ) ;
87+ await _subscriptionClient . AbandonAsync ( message . SystemProperties . LockToken ) ;
9788 }
9889 }
9990
10091 private Task ExceptionHandler ( ExceptionReceivedEventArgs arg )
10192 {
102- _logger . LogWarning (
103- default , arg . Exception , "Error on receiving events" ) ;
93+ _logger . LogWarning ( default , arg . Exception , "Error on receiving events" ) ;
10494
10595 return Task . CompletedTask ;
10696 }
0 commit comments