Per message options configuration for IMessagePublisher#341
Conversation
29b7178 to
661f525
Compare
normj
left a comment
There was a problem hiding this comment.
I like the idea of this PR. I might be over thinking this but just wondering if a user might need access to the services registered in the DI container. For example use some DI service that would be able to look up the group id based on a customer id on the on the message. In that case the service call might be async so it might be good then for the callbacks to return ValueTask.
…e required interface.
- Add async, DI-enabled per-message config for SQS/SNS/EventBridge publishers via new Action/Func overloads - MessageRoutingPublisher now resolves publishers from DI per publish (cached in DI provider) - Register IMessagePublisher as scoped, not singleton - Bump version to Major due to breaking API changes
|
@normj I have added per-message options configuration for publishing to the
Breaking changes:
These are both technically breaking changes, but may not warrant a full bump. builder.Services.AddAWSMessageBus(builder =>
{
// synchronous
builder.AddSQSPublisher<TransactionInfo>(
"https://sqs.us-west-2.amazonaws.com/012345678910/MyFifoQueue.fifo",
configureOptions: (serviceProvider, message, options) =>
{
options.MessageGroupId = message.TransactionId;
options.MessageDeduplicationId = message.TransactionId;
});
// asynchronous
builder.AddSNSPublisher<BidInfo>(
"arn:aws:sns:us-west-2:012345678910:MyFifoTopic.fifo",
configureOptions: async (serviceProvider, message, options, cancellationToken) =>
{
var service = serviceProvider.GetRequiredService<SomeService>();
var messageGroupId = service.GetMessageGroupIdAsync(message, cancellationToken0;
options.MessageGroupId = messageGroupId;
});
});I have left each commit unsquashed to make rollback, etc easier. Please modify/drop as you see fit. |
#340
Adds optional per-message
configureOptionscallbacks toIMessageBusBuilder.AddSQSPublisherandIMessageBusBuilder.AddSNSPublisher.With this change, applications using the generic
IMessagePublishercan populate SQS- and SNS-specific publish options from the message being sent. This enables scenarios such as publishing to FIFO queues and topics by deriving values likeMessageGroupIdandMessageDeduplicationIdfrom the message itself, while still using type-based routing throughIMessagePublisher.The change also allows these callbacks to override service-configured defaults for a given publish operation, providing additional flexibility when message-specific behavior is required. Documentation has been updated to describe this capability in the publishing guidance.
Example usage:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.