为什么不MassTransit消息使结构? [英] Why are structs not allowed in MassTransit messaging?

查看:149
本文介绍了为什么不MassTransit消息使结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MassTransit 消费者接口都期待的消息模型是类,而不是结构。因为他们都是内部接口(非常漂亮的设计有我必须说),这是一般的容器类呈现约束,采取直接的 nofollow的>:

The consumer interfaces in MassTransit all expect the message models to be classes and not structs. Since they are all inner interfaces (very nice design there I must say), this is the generic container class showing the constraint, taken directly from the source code:

/// <summary>
/// Declares a Consume method for the message type TMessage which is called
/// whenever a a message is received of the specified type.
/// </summary>
public static class Consumes<TMessage> where TMessage : class

这是不是随着技术的发展开始了人的问题,但它是一个麻烦给我们,因为我们已经有了,甚至考虑使用一个服务总线架构之前,关系到我们的codeBase的命令模式对象,所以我们不得不改变一大群的接口和通用类来添加约束他们与MT工作。

This is not a problem for people starting out with the technology, but it was a hassle to us, since we already had objects related to the command pattern in our codebase before even considering the use of a service bus framework, and so we had to change quite a bunch of interfaces and generic classes to add that constraint for them to work with MT.

我们很幸运的没有明确,虽然有任何结构类型的,因为这可能会导致更多的(也许是不必要的)的变化。

We were lucky for not explicitly having any struct types though, since that would probably cause even more (perhaps unwanted) changes.

为什么它需要消息类是一个?有没有可能改变这种状况,让库接口更加无缝地与现有的code?我估计,该约束没有不加的,所以有可能是一些并发症。

Why does it require the message classes to be a class? Would it be possible to change that, so that the library interfaces more seamlessly with existing code? I figure that the constraint was not added for nothing though, so there are probably some complications.

推荐答案

在现实中,所有的消息的合同应该是接口。抽象应该从任何逻辑被删除,接口会强制执行。您也可以撰写交付以有趣的方式,因为MT将提供给在继承/实现层次所有匹配的路由。

In reality, all your message contracts should be interfaces. The abstraction should be removed from any logic and interfaces would enforce that. You can also compose delivery in interesting ways since MT will deliver to all matching routes in the inheritance/implementation hierarchy.

但不管是什么,我们提出一个确实的消息,事实证明,值类型是行不通的,我们用它们的方式。我们很大程度上取决于类型的信息,我们可以创建代理的传递到你的客户类型。

But regardless of what we suggest one does for the messages, it turns out that value types will not work the way we use them. We heavily depend upon type information and we can create proxies for the types delivered to your consumers.

这篇关于为什么不MassTransit消息使结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆