1
1
using System . IO ;
2
- using System . Threading ;
3
2
using Common . Logging ;
4
3
using NServiceBus . Config ;
5
4
using NServiceBus . MessageMutator ;
@@ -11,7 +10,7 @@ namespace NServiceBus.Unicast.BackwardCompatibility
11
10
/// <summary>
12
11
/// Allow for a V3.X subscriber to subscribe/unsubscribe to a V2.6 publisher
13
12
/// </summary>
14
- public class MutateTransportOutgoingSubscriptionMessages : IMutateOutgoingTransportMessages , INeedInitialization
13
+ public class OutgoingSubscriptionMessageMutator : IMutateOutgoingTransportMessages , INeedInitialization
15
14
{
16
15
/// <summary>
17
16
/// Allow for a V3.X subscriber to subscribe/unsubscribe to a V2.6 publisher
@@ -23,26 +22,32 @@ public class MutateTransportOutgoingSubscriptionMessages : IMutateOutgoingTransp
23
22
public void MutateOutgoing ( object [ ] messages , TransportMessage transportMessage )
24
23
{
25
24
if ( ( transportMessage . IsControlMessage ( ) &&
26
- ( ( transportMessage . MessageIntent == MessageIntentEnum . Subscribe ) || ( transportMessage . MessageIntent == MessageIntentEnum . Unsubscribe ) ) ) )
25
+ ( ( transportMessage . MessageIntent == MessageIntentEnum . Subscribe ) ||
26
+ ( transportMessage . MessageIntent == MessageIntentEnum . Unsubscribe ) ||
27
+ ( transportMessage . MessageIntent == MessageIntentEnum . Send ) ) ) )
27
28
{
28
29
var stream = new MemoryStream ( ) ;
29
- MessageSerializer . Serialize ( new object [ ] { new CompletionMessage ( ) } , stream ) ;
30
+ var completionMessage = new CompletionMessage ( ) ;
31
+ if ( transportMessage . Headers . ContainsKey ( Headers . ReturnMessageErrorCodeHeader ) )
32
+ completionMessage . ErrorCode = int . Parse ( transportMessage . Headers [ Headers . ReturnMessageErrorCodeHeader ] ) ;
33
+
34
+ MessageSerializer . Serialize ( new object [ ] { completionMessage } , stream ) ;
30
35
transportMessage . Body = stream . ToArray ( ) ;
31
36
Log . Debug ( "Added Completion message and sending message intent: " + transportMessage . MessageIntent ) ;
32
37
}
33
38
}
34
39
35
40
/// <summary>
36
- /// Register the MutateTransportOutgoingSubscriptionMessages mutator
41
+ /// Register the OutgoingSubscriptionMessageMutator mutator
37
42
/// </summary>
38
43
public void Init ( )
39
44
{
40
- Configure . Instance . Configurer . ConfigureComponent < MutateTransportOutgoingSubscriptionMessages > ( DependencyLifecycle . InstancePerCall ) ;
45
+ Configure . Instance . Configurer . ConfigureComponent < OutgoingSubscriptionMessageMutator > ( DependencyLifecycle . InstancePerCall ) ;
41
46
}
42
47
/// <summary>
43
48
/// Gets or sets the message serializer
44
49
/// </summary>
45
50
public IMessageSerializer MessageSerializer { get ; set ; }
46
- private readonly static ILog Log = LogManager . GetLogger ( typeof ( MutateTransportOutgoingSubscriptionMessages ) ) ;
51
+ private readonly static ILog Log = LogManager . GetLogger ( typeof ( OutgoingSubscriptionMessageMutator ) ) ;
47
52
}
48
53
}
0 commit comments