22using System . Collections . Generic ;
33using System . Text ;
44using System . Threading ;
5+ using System . Threading . Tasks ;
56using InEngine . Core . Exceptions ;
67using InEngine . Core . IO ;
78using InEngine . Core . Queuing . Message ;
@@ -94,13 +95,18 @@ public void Recover()
9495 {
9596 }
9697
97- public void Consume ( CancellationToken cancellationToken )
98+ public async Task Consume ( CancellationToken cancellationToken )
9899 {
99100 InitChannel ( ) ;
100101 var consumer = new EventingBasicConsumer ( Channel ) ;
101- consumer . Received += ( model , result ) =>
102+ consumer . Received += async ( model , result ) =>
102103 {
103104 var eventingConsumer = ( EventingBasicConsumer ) model ;
105+ if ( eventingConsumer == null )
106+ {
107+ Log . LogWarning ( "EventingBasicConsumer is null while attempting to consume messages" ) ;
108+ return ;
109+ }
104110
105111 var serializedMessage = Encoding . UTF8 . GetString ( result . Body ) ;
106112 var commandEnvelope = serializedMessage . DeserializeFromJson < CommandEnvelope > ( ) ;
@@ -115,7 +121,7 @@ public void Consume(CancellationToken cancellationToken)
115121 try
116122 {
117123 command . WriteSummaryToConsole ( ) ;
118- command . RunWithLifeCycleAsync ( ) . RunSynchronously ( ) ;
124+ await command . RunWithLifeCycleAsync ( ) ;
119125 }
120126 catch ( Exception exception )
121127 {
@@ -135,7 +141,7 @@ public void Consume(CancellationToken cancellationToken)
135141 Channel . BasicConsume ( queue : PendingQueueName , autoAck : false , consumer : consumer ) ;
136142 }
137143
138- public ICommandEnvelope Consume ( )
144+ public async Task < ICommandEnvelope > Consume ( )
139145 {
140146 InitChannel ( ) ;
141147 var result = Channel . BasicGet ( PendingQueueName , false ) ;
@@ -155,7 +161,7 @@ public ICommandEnvelope Consume()
155161 try
156162 {
157163 command . WriteSummaryToConsole ( ) ;
158- command . RunWithLifeCycleAsync ( ) . RunSynchronously ( ) ;
164+ await command . RunWithLifeCycleAsync ( ) ;
159165 }
160166 catch ( Exception exception )
161167 {
0 commit comments