0
votes

I'm running a MassTransit configuration with AmazonSQS. In my program I start by creating a receiveenpoint with the queue "input-queue1", I subscribe this SQS queue to an SNS topic named "topic1" and associate a consumer to this receiveendpoint that does some standard printing of the messages it receives. After starting the bus i want to subscribe the already created queue "input-queue1" to another SNS topic, named "topic2", but I couldn't find a way of doing this after starting the Bus (It's important to me that i can do this after the Bus is started). Is there a way of doing this and i'm just missing something, or is it not possible at all? (I tried with the commented portion of the code but it didn't work)

class Program
    {
        static async Task Main(string[] args)
        {
            var bus = Bus.Factory.CreateUsingAmazonSqs(x =>
            {
                x.Host(Constants.Region, h =>
                {
                    h.AccessKey(Constants.AccesskeyId);
                    h.SecretKey(Constants.SecretAccessKey);
                });

                x.ReceiveEndpoint("input-queue1", e =>
                {
                    e.Subscribe("topic1", callback => { });

                    e.Consumer(() => new Handler());
                });

            });

            bus.StartAsync().Wait();

            /*var handle = bus.ConnectReceiveEndpoint("input-queue1", e => {
                e.Subscribe("topic2", callback => { });
            });
            var ready = await handle.Ready;*/

            Console.WriteLine("Listening to messages...");
            Console.WriteLine("Press enter to quit");
            Console.ReadLine();
        }
    }
1

1 Answers

0
votes

You can't change the topology of a receive endpoint once it has been created. This means that no new topic subscriptions can be created, and existing subscriptions cannot be removed.

If you need to change the configuration of the receive endpoint, you would need to do it yourself by using the SNS API to add the subscription yourself. I would question why you would want to do this though. If the consumer isn't able to consume the message forwarded to the queue, it would be moved to the skipped queue.