【问题标题】:MassTransit Send Only Message BodyMassTransit 仅发送消息正文
【发布时间】:2021-11-09 00:07:04
【问题描述】:

正在研究使用 MassTransit 来替换我公司正在使用的一些旧的、脆弱的 ActiveMQ 库。目前我们发送给 AMQ 的消息基本上只是对象

{
    "clientId": 1,
    "accountid": 333,
    "filePath": "C:\Test.csv",
    "updateDate": "2021-11-08T23:37:39.2915758Z"
}

不过,当我通过 MassTransit 发送消息时,它会在消息中添加大量其他信息...

{
  "messageId": "00010000-4100-0250-5531-08d9a310c15e",
  "conversationId": "00010000-4100-0250-577a-08d9a310c15e",
  "sourceAddress": "activemq://localhost:61616/WINDOWZZZ123_MyCompanyStreamService_bus_yyyoyynbyybfynjjbdc4grfire?temporary=true",
  "destinationAddress": "activemq://localhost:61616/MessageQueue_Testing",
  "messageType": [
    "urn:message:MyCompany.Services.QueueContracts:MessageQueueItem",
    "urn:message:MyCompany.Services.QueueContracts:IQueueItem"
  ],
  "message": {
    "clientId": 1,
    "accountId": 333,
    "filePath": "C:\Test.csv",
    "updateDate": "2021-11-08T23:37:39.2915758Z"
  },
  "sentTime": "2021-11-08T23:37:40.8624945Z",
  "headers": {
    "MT-Activity-Id": "00-b8b6cf020495eb44b57c8eff14244671-937ecff1f3901d41-01"
  },
  "host": {
    "machineName": "WINDOWZZZ123",
    "processName": "MyCompany.StreamService",
    "processId": 25692,
    "assembly": "MyCompany.StreamService",
    "assemblyVersion": "1.0.0.0",
    "frameworkVersion": "5.0.11",
    "massTransitVersion": "7.2.4.0",
    "operatingSystemVersion": "Microsoft Windows NT 10.0.19043.0"
  }
}

虽然我看到拥有所有这些元数据的价值,但它会破坏我们所有的旧服务,而且目前工作量太大。

我正在像这样设置 MassTransit... Startup.cs ConfigureServes()

services.AddMassTransit(x =>
{
    x.UsingActiveMq((context, cfg) =>
    {
        cfg.Host("localhost", h =>
        {
            h.Username("admin");
            h.Password("admin");
        });
    });
});
services.AddMassTransitHostedService();

我正在发送这样的消息....

var endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("queue:myQueue"));
var item = new MessageQueueItem();
await endpoint.Send<MessageQueueItem>(item);

从查看文档看来,MassTransit 似乎并不是真正为这个用例而构建的,而是更适合构建所有使用 MT 协同工作的系统?

感谢您的帮助! -格雷格

【问题讨论】:

    标签: c# masstransit


    【解决方案1】:

    如果需要,您可以切换到原始 JSON 序列化程序,只需更改您的总线配置:

    services.AddMassTransit(x =>
    {
        x.UsingActiveMq((context, cfg) =>
        {
            cfg.Host("localhost", h =>
            {
                h.Username("admin");
                h.Password("admin");
            });
    
            cfg.UseRawJsonSerializer();
        });
    });
    services.AddMassTransitHostedService();
    

    这将只发送消息,没有消息信封。

    【讨论】:

    • 传奇本人:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多