Search code examples
c#amazon-sqsamazon-snsmasstransit

MassTransit - AWS SQS/SNS - add tags to SNS


I have a need to configure the MassTransit library in a way that I maintain the tags for SNS.

I can see the places to configure the Tags for the SQS Queues that are created - and that works as expected. However, I need to do a similar thing for SNS Topics that MassTransit creates.

There is a couple of things I've tried so far, unfortunately, none of them allowed me to create tags on the SNS resource.

public IBusControl GetServiceBus()
    {
        var serviceBus = Bus.Factory.CreateUsingAmazonSqs(sbc =>
        {
            sbc.Host("AmazonRegion", h =>
            {
                    h.Config(
                        new AmazonSimpleNotificationServiceConfig
                        {
                            ServiceURL = _configService.AmazonSnsServiceUrl
                            //Tags doesn't seems the be available here
                        });

                    h.Config(new AmazonSQSConfig
                    {
                        ServiceURL = _configService.AmazonSqsServiceUrl
                    });

                    h.AccessKey("AccessKey");
                    h.SecretKey("SecretKey");
            });
            sbc.ReceiveEndpoint("queueName", e =>
            {
                e.Consumer<IConsumer<Message>>(_container);
                e.Consumer<IConsumer<Fault<Message>>>(_container);
                e.QueueTags.Add("TestTag", "DEV");
                //Here I can define only Tags for the queue, not for the Topic though
            });
        });
        serviceBus.ConnectSendAuditObservers(_messageAuditStore);
        serviceBus.ConnectConsumeAuditObserver(_messageAuditStore);
        return serviceBus;
    }

I tried also do a manual Subscription like that:

e.Subscribe<T>(cfg =>
        {
            cfg.TopicTags.Add("TestTag", "test");
         });

But that didn't work too.

I know there is an option to subscribe to pre-created Topics with MassTransit, but I feel that is rather a restriction, and I'd like to use the flexibility of MassTransit for managing the types.

Is there something I am missing here? Thank you.


Solution

  • To configure topic tags/attributes, you need to configure the topic topology, which is done by configuring the Publish topology.

    For instance, to add a tag for the Message type, you would specify:

    configurator.Publish<Message>(p =>
    {
        p.TopicTags.Add("hello", "world");
    });