@@ -4,12 +4,8 @@ namespace MassTransit.Context
44 using System ;
55 using System . Collections . Generic ;
66 using System . Diagnostics . CodeAnalysis ;
7- using System . Linq ;
87 using System . Threading ;
98 using System . Threading . Tasks ;
10- using Events ;
11- using Metadata ;
12- using Middleware ;
139 using Transports ;
1410
1511
@@ -253,22 +249,10 @@ async Task RespondInternalAsync()
253249 return RespondInternalAsync ( ) ;
254250 }
255251
256- protected virtual async Task GenerateFault < T > ( ConsumeContext < T > context , Exception exception )
252+ protected virtual Task GenerateFault < T > ( ConsumeContext < T > context , Exception exception )
257253 where T : class
258254 {
259- if ( context . ReceiveContext . PublishFaults || context . FaultAddress != null || context . ResponseAddress != null )
260- {
261- Fault < T > fault = new FaultEvent < T > ( context . Message , context . MessageId , HostMetadataCache . Host , exception ,
262- context . SupportedMessageTypes . ToArray ( ) ) ;
263-
264- var faultPipe = new FaultPipe < T > ( context ) ;
265-
266- var faultContext = InternalOutboxExtensions . SkipOutbox ( context ) ;
267-
268- var faultEndpoint = await faultContext . GetFaultEndpoint < T > ( ) . ConfigureAwait ( false ) ;
269-
270- await faultEndpoint . Send ( fault , faultPipe , context . CancellationToken ) . ConfigureAwait ( false ) ;
271- }
255+ return context . GenerateFault ( exception ) ;
272256 }
273257
274258 Task ConsumeTask ( Task task )
@@ -284,41 +268,5 @@ protected override async Task<ISendEndpoint> GetPublishSendEndpoint<T>()
284268
285269 return new ConsumeSendEndpoint ( publishSendEndpoint , this ) ;
286270 }
287-
288-
289- class FaultPipe < T > :
290- IPipe < SendContext < Fault < T > > >
291- where T : class
292- {
293- readonly ConsumeContext < T > _context ;
294-
295- public FaultPipe ( ConsumeContext < T > context )
296- {
297- _context = context ;
298- }
299-
300- public Task Send ( SendContext < Fault < T > > context )
301- {
302- context . TransferConsumeContextHeaders ( _context ) ;
303-
304- context . CorrelationId = _context . CorrelationId ;
305- context . RequestId = _context . RequestId ;
306-
307- if ( _context . TryGetPayload ( out ConsumeRetryContext ? consumeRetryContext ) && consumeRetryContext . RetryCount > 0 )
308- context . Headers . Set ( MessageHeaders . FaultRetryCount , consumeRetryContext . RetryCount ) ;
309- else if ( _context . TryGetPayload ( out RetryContext ? retryContext ) && retryContext . RetryCount > 0 )
310- context . Headers . Set ( MessageHeaders . FaultRetryCount , retryContext . RetryCount ) ;
311-
312- var redeliveryCount = _context . Headers . Get < int > ( MessageHeaders . RedeliveryCount ) ;
313- if ( redeliveryCount . HasValue )
314- context . Headers . Set ( MessageHeaders . FaultRedeliveryCount , redeliveryCount ) ;
315-
316- return Task . CompletedTask ;
317- }
318-
319- public void Probe ( ProbeContext context )
320- {
321- }
322- }
323271 }
324272}
0 commit comments