Skip to content

Commit

Permalink
Merge pull request #6913 from Particular/add-rabbit-customization-docs
Browse files Browse the repository at this point in the history
Add docs about NativeOutgoingMessageCustomization in RabbitMQ
  • Loading branch information
SzymonPobiega authored Nov 25, 2024
2 parents aa71c88 + 5597380 commit 39fe25a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Snippets/Rabbit/Rabbit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rabbit_9", "Rabbit_9\Rabbit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rabbit_9.1", "Rabbit_9.1\Rabbit_9.1.csproj", "{FE4D23D8-5327-4106-B78A-21888BE48262}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rabbit_9.2", "Rabbit_9.2\Rabbit_9.2.csproj", "{2F242592-4E40-4C87-90A4-32055B11544F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -45,6 +47,10 @@ Global
{FE4D23D8-5327-4106-B78A-21888BE48262}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE4D23D8-5327-4106-B78A-21888BE48262}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE4D23D8-5327-4106-B78A-21888BE48262}.Release|Any CPU.Build.0 = Release|Any CPU
{2F242592-4E40-4C87-90A4-32055B11544F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F242592-4E40-4C87-90A4-32055B11544F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F242592-4E40-4C87-90A4-32055B11544F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F242592-4E40-4C87-90A4-32055B11544F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
23 changes: 23 additions & 0 deletions Snippets/Rabbit/Rabbit_9.2/OutgoingNativeMessageCustomization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NServiceBus;

class OutgoingNativeMessageCustomization
{
OutgoingNativeMessageCustomization(EndpointConfiguration endpointConfiguration)
{
#region rabbitmq-customize-outgoing-message

var rabbitMqTransport = new RabbitMQTransport(
routingTopology: RoutingTopology.Conventional(QueueType.Classic),
connectionString: "host=localhost;username=rabbitmq;password=rabbitmq",
enableDelayedDelivery: false
);

rabbitMqTransport.OutgoingNativeMessageCustomization = (operation, properties) =>
{
//Set values on IBasicProperties
properties.ContentType = "application/my-type";
};

#endregion
}
}
8 changes: 8 additions & 0 deletions Snippets/Rabbit/Rabbit_9.2/Rabbit_9.2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NServiceBus.RabbitMQ" Version="9.2.*" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion transports/rabbitmq/native-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ redirects:

This document describes how to consume messages from and send messages to non-NServiceBus endpoints via RabbitMQ in integration scenarios.

### Access to the native RabbitMQ message details
### Access to the received native RabbitMQ message details

It can sometimes be useful to access the native RabbitMQ message from behaviors and handlers. When a message is received, the transport adds the native RabbitMQ client [`BasicDeliverEventArgs`](https://rabbitmq.github.io/rabbitmq-dotnet-client/api/RabbitMQ.Client.Events.BasicDeliverEventArgs.html) to the message processing context. Use the code below to access the message details from a [pipeline behavior](/nservicebus/pipeline/manipulate-with-behaviors.md):

snippet: rabbitmq-access-to-event-args

partial: outgoing-customization

### Custom message ID strategy

By default, the `message-id` property of the AMQP standard is used to relay the [message identity](/nservicebus/messaging/message-identity.md). If this property isn't set, the transport will throw an exception because NServiceBus requires a message identity to perform retries, de-duplication, etc., in a safe way.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Access to the native RabbitMQ message details prior to sending

When integrating with other software systems it might be necessary to customize the native RabbitMQ message immediately before sending it to the broker. This can be done by registering a callback that gets invoked for each message as a last step before handing the message to the RabbitMQ client SDK.

snippet: rabbitmq-customize-outgoing-message

0 comments on commit 39fe25a

Please sign in to comment.