Skip to content

AzureServiceBusScheduler.ConvertToServiceBusMessage writes RoutingKey instance into AMQP ApplicationProperties[ReplyTo] #4150

Description

@Jonny-Freemarket

Describe the bug

Paramore.Brighter.MessageScheduler.Azure.AzureServiceBusScheduler.ConvertToServiceBusMessage writes message.Header.ReplyTo (a Paramore.Brighter.RoutingKey struct) directly into ServiceBusMessage.ApplicationProperties["ReplyTo"]. AMQP cannot serialise this — sending throws SerializationException: "unsupported type, Paramore.Brighter.RoutingKey".

The non-scheduler ASB publisher (AzureServiceBusMessagePublisher) correctly writes the string value ReplyTo.Value to the same key. The scheduler diverges from that established behaviour, which makes the scheduler unusable for any message with ReplyTo set.

To Reproduce

var scheduler = /* construct AzureServiceBusScheduler */;
var message = new Message(
    new MessageHeader(Id.Random(), new RoutingKey("topic"), MessageType.MT_EVENT)
    {
        ReplyTo = new RoutingKey("reply-topic")
    },
    new MessageBody("payload"));

// Throws on send
await scheduler.ScheduleAsync(message, TimeSpan.FromMinutes(1));

Exceptions

System.Runtime.Serialization.SerializationException: unsupported type, Paramore.Brighter.RoutingKey
   at Microsoft.Azure.Amqp.Encoding.AmqpEncoding.GetEncoding(...)
   at Azure.Messaging.ServiceBus.AmqpMessageConverter...
   at Azure.Messaging.ServiceBus.ServiceBusSender.ScheduleMessageAsync(...)
   at Paramore.Brighter.MessageScheduler.Azure.AzureServiceBusScheduler.ScheduleAsync(...)

Suggested fix

In ConvertToServiceBusMessage, mirror AzureServiceBusMessagePublisher:

- azureServiceBusMessage.ApplicationProperties.Add("ReplyTo", message.Header.ReplyTo);
+ azureServiceBusMessage.ApplicationProperties.Add("ReplyTo", message.Header.ReplyTo?.Value);

Further technical details

  • Brighter version: 10.4.1 (Paramore.Brighter.MessageScheduler.Azure)
  • dotnet --info:
    .NET SDK 10.0.108 (commit 94ea82652c, MSBuild 18.0.11+94ea82652)
    Host 10.0.8 (x64)
    RID: win-x64
    
  • OS: Windows 11 (build 10.0.26200)

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions