Added CustomHeaders support to Azure Service Bus transport (#1063)
* Updated docs
* Added CustomHeaders property to CAP.AzureServiceBusOptions.cs
* Merged upstream/master
* Updated docs
* Verified if a custom header with the same key is already present
@@ -73,7 +73,7 @@ cap-msg-type | string | The type of message, `typeof(T).FullName`(not required)
cap-senttime | string | sending time (not required)
### Custom headers
To consume messages sent without CAP headers, both Kafka and RabbitMQ consumers can inject a minimal set of headers using custom headers as shown below:
To consume messages sent without CAP headers, both AzureServiceBus, Kafka and RabbitMQ consumers can inject a minimal set of headers using the `CustomHeaders` property as shown below (RabbitMQ example):
```C#
container.AddCap(x =>
{
@@ -89,7 +89,7 @@ container.AddCap(x =>
});
```
After adding `cap-msg-id` and `cap-msg-name`, CAP consumers receive messages sent directly from the RabbitMQ management tool.
After adding `cap-msg-id` and `cap-msg-name`, CAP consumers receive messages sent directly from any external system, like the RabbitMQ management tool when using RabbitMQ as a transport.
## Scheduling
+ 26- 7
docs/content/user-guide/en/transport/azure-service-bus.mdVoir le fichier
@@ -38,13 +38,13 @@ public void ConfigureServices(IServiceCollection services)
The AzureServiceBus configuration options provided directly by the CAP:
NAME | DESCRIPTION | TYPE | DEFAULT
:---|:---|---|:---
ConnectionString | Endpoint address | string |
EnableSessions | Enable [Service bus sessions](https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-sessions) | bool | false
If no session id header is present, the message id will be used as the session id.
#### Heterogeneous Systems
Sometimes you might want to listen to a message that was published by an external system. In this case, you need to add a set of two mandatory headers for CAP compatibility as shown below.
```csharp
c.UseAzureServiceBus(asb =>
{
asb.ConnectionString = ...
asb.CustomHeaders = message => new List<KeyValuePair<string, string>>()
src/DotNetCore.CAP.AzureServiceBus/CAP.AzureServiceBusOptions.csVoir le fichier
@@ -1,7 +1,10 @@
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using DotNetCore.CAP.AzureServiceBus;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Primitives;
// ReSharper disable once CheckNamespace
@@ -36,6 +39,11 @@ namespace DotNetCore.CAP
/// <summary>
/// Represents the Azure Active Directory token provider for Azure Managed Service Identity integration.
/// </summary>
public ITokenProvider? ManagementTokenProvider { get; set; }
public ITokenProvider? ManagementTokenProvider { get; set; }
/// <summary>
/// Use this function to write additional headers from the original ASB Message or any Custom Header, i.e. to allow compatibility with heterogeneous systems, into <see cref="CapHeader"/>
/// </summary>
public Func<Message, List<KeyValuePair<string, string>>>? CustomHeaders { get; set; }