Search code examples
amazon-sqsmasstransit

MassTransit Consuming Raw Json from an existing SQS queue


I have an app that is consuming raw json from a pre-existing SQS queue for interoperability with another system. We're using the Amazon Sqs client (.Net Sdk). I'd like to switch this to have a MassTransit consumer pull the raw json.

I've watched the video that shows how to Bind to a RabbitMQ queue to consume messages without MT wrappers, but I can't see how to subscribe the consumer to SQS manually.

There is no sns topic, just the sqs queue.

IAmazonSqsReceiveEndpointConfigurator only has Subscribe methods that refer to topics.


Solution

  • Consuming raw JSON from an SQS with MassTransit is easy.

    services.AddMassTransit(x =>
    {
        x.AddConsumer<SomeConsumer>();
    
        x.UsingAmazonSqs((context, cfg) =>
        {
            cfg.Host(...);
    
            cfg.ReceiveEndpoint("existing-sqs-queue", e =>
            {
                e.UseRawJsonSerializer(isDefault: true);
    
                e.ConfigureConsumer<SomeConsumer>();
            });
        });    
    });
    

    Any message on the queue will be delivered to the consumer.