MassTransit 从现有的 SQS 队列中消费原始 JSON 数据

huangapple go评论57阅读模式
英文:

MassTransit Consuming Raw Json from an existing SQS queue

问题

我有一个应用程序,它正在从一个现有的SQS队列中消耗原始JSON以与另一个系统进行互操作。我们正在使用Amazon SQS客户端(.Net SDK)。我想将这个过渡到使用MassTransit消费者来拉取原始JSON。

我已经观看了显示如何绑定到RabbitMQ队列以消费没有MT包装的消息的视频,但我看不到如何手动订阅消费者到SQS。

IAmazonSqsReceiveEndpointConfigurator只有与主题相关的Subscribe方法,没有与SQS相关的方法。

英文:

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.

答案1

得分: 1

使用MassTransit从SQS消耗原始JSON很容易。

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>();
        });
    });    
});

队列上的任何消息都将传递给消费者。

英文:

Consuming raw JSON from an SQS with MassTransit is easy.

services.AddMassTransit(x =&gt;
{
    x.AddConsumer&lt;SomeConsumer&gt;();

    x.UsingAmazonSqs((context, cfg) =&gt;
    {
        cfg.Host(...);

        cfg.ReceiveEndpoint(&quot;existing-sqs-queue&quot;, e =&gt;
        {
            e.UseRawJsonSerializer(isDefault: true);

            e.ConfigureConsumer&lt;SomeConsumer&gt;();
        });
    });    
});

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

huangapple
  • 本文由 发表于 2023年6月22日 01:25:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525780.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定