-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1494 from Particular/set-native-content-type-9-2
Allow setting customizing the outgoing messages by setting AMQP attributes just before dispatching the message to the broker
- Loading branch information
Showing
6 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/NServiceBus.Transport.RabbitMQ.AcceptanceTests/When_customizing_outgoing_messages.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace NServiceBus.Transport.RabbitMQ.AcceptanceTests | ||
{ | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using global::RabbitMQ.Client.Events; | ||
using NServiceBus.AcceptanceTests; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
|
||
class When_customizing_outgoing_messages : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_set_native_property_value() | ||
{ | ||
var scenario = await Scenario.Define<Context>() | ||
.WithEndpoint<Receiver>(b => b.When((bus, c) => bus.SendLocal(new Message()))) | ||
.Done(c => c.MessageReceived) | ||
.Run(); | ||
|
||
Assert.That(scenario.BasicDeliverEventArgs.BasicProperties.AppId, Is.EqualTo("MyValue")); | ||
} | ||
|
||
public class Receiver : EndpointConfigurationBuilder | ||
{ | ||
public Receiver() | ||
{ | ||
EndpointSetup<DefaultServer>(endpointConfiguration => | ||
{ | ||
endpointConfiguration.ConfigureRabbitMQTransport().OutgoingNativeMessageCustomization = | ||
(operation, properties) => | ||
{ | ||
properties.AppId = "MyValue"; | ||
}; | ||
}); | ||
} | ||
|
||
class MyEventHandler : IHandleMessages<Message> | ||
{ | ||
Context testContext; | ||
|
||
public MyEventHandler(Context testContext) | ||
{ | ||
this.testContext = testContext; | ||
} | ||
|
||
public Task Handle(Message message, IMessageHandlerContext context) | ||
{ | ||
testContext.BasicDeliverEventArgs = context.Extensions.Get<BasicDeliverEventArgs>(); | ||
testContext.MessageReceived = true; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
public class Message : IMessage | ||
{ | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool MessageReceived { get; set; } | ||
|
||
public BasicDeliverEventArgs BasicDeliverEventArgs { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters