.net-core - 轨道交通。编辑 MessageType 属性以删除不必要的项目

标签 .net-core microservices azureservicebus masstransit

首先,请原谅我的英语,非常糟糕。我将 MassTransit 与 Azure 服务总线结合使用,以实现微服务之间的异步通信。

由于项目设计要求,大众运输中发送和/或发布的对象是实现接口(interface)并具有继承性的对象(类实例),这意味着“MessageType”属性是多个值的数组,这会导致为对象的每个基类和接口(interface)发送/发布对象的“副本”。

由于应用程序实际上只需要处理最终类,因此此行为的结果是创建了从未处理的消息类型的队列和主题。

有没有办法修改 MessageType 数组以删除所有不必要的项目?

示例:

这是一条当前消息:

{
  "messageId": "c93e0000-eab0-3663-c954-08d89e1f87cb",
  "correlationId": "42fc2237-77b1-4994-821d-87790b6caf06",
  "conversationId": "c93e0000-eab0-3663-f342-08d89e1f87cd",
  "sourceAddress": "sb://bus.servicebus.windows.net/tmspayments7dc9d65778jfh75_dotnet_bus_3r9yyy8ksy5g84tdbdcjasmhg9",
  "destinationAddress": "sb://bus.servicebus.windows.net/queue",
  "messageType": [
    "urn:message:Payments.Application.Integration.Outcoming.Commands.Sales:NotifySalePaymentHasCanceledCommand",
    "urn:message:Payments.Application.Integration.Outcoming.Commands:BaseIntegrationOutcomingCommand",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Commands:IdentifiedCommandBase",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Messages:MessageBase",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Messages:IIdentifiedMessage",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Messages:IMessage",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Commands:IIdentifiedCommand",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Messages:ICommand",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Commands.Outcoming:IOutcomingCommand",
    "urn:message:Tms.Frameworks.CqrsEs.Cqrs.Messages:IOutcomingMessage"
  ],
  "message": {
    "commandId": "42fc2237-77b1-4994-821d-87790b6caf06",
    "terminalId": 71,
    "paymentId": "a28a23e9-3ba5-464f-9a20-d25d1991ab46"
  },
  "sentTime": "2020-12-11T21:55:53.252599Z",
  "headers": {},
  "host": {
    "machineName": "tms-payments-7dc9d65778-jfh75",
    "processName": "dotnet",
    "processId": 1,
    "assembly": "Payments.Api",
    "assemblyVersion": "1.0.0.0",
    "frameworkVersion": "3.1.8",
    "massTransitVersion": "5.5.2.0",
    "operatingSystemVersion": "Unix 4.15.0.1098"
  }
}

这是我的目标消息(messageType 属性中只有一项):

{
  "messageId": "c93e0000-eab0-3663-c954-08d89e1f87cb",
  "correlationId": "42fc2237-77b1-4994-821d-87790b6caf06",
  "conversationId": "c93e0000-eab0-3663-f342-08d89e1f87cd",
  "sourceAddress": "sb://bus.servicebus.windows.net/tmspayments7dc9d65778jfh75_dotnet_bus_3r9yyy8ksy5g84tdbdcjasmhg9",
  "destinationAddress": "sb://bus.servicebus.windows.net/queue",
  "messageType": [
    "urn:message:Payments.Application.Integration.Outcoming.Commands.Sales:NotifySalePaymentHasCanceledCommand"
  ],
  "message": {
    "commandId": "42fc2237-77b1-4994-821d-87790b6caf06",
    "terminalId": 71,
    "paymentId": "a28a23e9-3ba5-464f-9a20-d25d1991ab46"
  },
  "sentTime": "2020-12-11T21:55:53.252599Z",
  "headers": {},
  "host": {
    "machineName": "tms-payments-7dc9d65778-jfh75",
    "processName": "dotnet",
    "processId": 1,
    "assembly": "Payments.Api",
    "assemblyVersion": "1.0.0.0",
    "frameworkVersion": "3.1.8",
    "massTransitVersion": "5.5.2.0",
    "operatingSystemVersion": "Unix 4.15.0.1098"
  }
}

非常感谢。

问候

博尔哈

最佳答案

简短回答:否

MassTransit 将反射(reflect)所有支持的类型并将它们包含在消息信封中以支持多态消息传递和反序列化。

您可以exclude message types避免在消息代理上创建为交换/主题,但这并不会将它们在序列化期间从消息类型数组中排除。

关于.net-core - 轨道交通。编辑 MessageType 属性以删除不必要的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65682706/

相关文章:

.net-core - .Net Core EventLog - 覆盖未处理的异常写入应用程序日志

asp.net - .Net 核心 : Set a user as logged in and authenticated

angularjs - *** process.env.ENV未定义,假设env为 'prod'

azure - Windows Azure 服务总线和 Windows Azure 虚拟网络之间的区别

azure - 没有可用于使用锁定 token 逻辑应用程序完成消息的 session

c# - .NET CORE 中的 "Specified cipher mode is not valid for this algorithm"但在 .NET Standard 中工作

c# - .Net Core - 复制到剪贴板?

architecture - 单一数据库支持的微服务器架构?

kubernetes - Istio Envoy 504 网关在出站连接 15 秒后超时

java - 使用 ServiceBusReceiverAsyncClient 的 Azure 服务总线不并发使用 Java