使用 NServiceBus 时如何在应用程序之间共享消息类?
所以我有两个独立的应用程序,我想在它们之间发送消息。 我碰巧正在使用 NServiceBus,但这并不重要。 如何从应用程序 A 向应用程序 B 发送消息并让它们都知道同一个合约?
所以应用程序 A 有一个类 SecretMessage...
public class SecretMessage : IMessage
{
public string Title { get; set; }
public string Body { get; set; }
}
这是将被序列化并通过线路发送到应用程序 B 的对象。
现在在应用程序 B 中,我如何侦听该类型的消息,然后能够de-将它们序列化到同一个类? 因此我可以在发送数据时使用数据,而不会成为维护的噩梦。
应用程序 B 是否只需要拥有该类的副本? 这是否应该通过每个应用程序都引用的消息类的共享 dll 来处理(我希望不是)? 是否应该在每个应用程序中将它们重新创建为具有相同属性的完全独立的 DTO?
我在这里错过了什么吗?
So I have two separate applications that I want to send messages between. I happen to be using NServiceBus, but that shouldn't really matter. How do I send a message from application A to application B and have them both be aware of the same contract?
So app A has a class SecretMessage...
public class SecretMessage : IMessage
{
public string Title { get; set; }
public string Body { get; set; }
}
This is the object that will be serialized and sent over the wire to app B.
Now in app B, how do I listen for messages that are of that type and then be able to de-serialze them to the same class? So I can use the data as it was sent, without this being a maintenance nightmare.
Does app B just have to have a copy of the class? Should this be handled through a shared dll of message classes that each app has a reference to (I hope not)? Should they be recreated in each app as completely separate DTO's with the same properties?
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不是您想要的答案,但这里的灵丹妙药很少。
您实际上只有几个选择,因此取决于您在消息类中想要的功能级别和类型强化:
这些确实是唯一的选择。 恕我直言,#2 然后#1 按此顺序通常是最有用的模式。
It may not be the answer you want but there are very few silver bullets here.
You've really only got a few choices, and as such then depends on the level of functionality and type-hardening you want in your message classes:
Those really are the only choices. IMHO #2 then #1 in that order are typically the most useful patterns.
正如 Juval Lowy 在《编程 .NET 组件》中所建议的,将纯接口分开自己的共享DLL。
http://arcanecode.com/2007 /02/14/more-oop-interfaces-in-c-part-2/
As suggested by Juval Lowy in Programming .NET Components, separate pure interfaces in their own shared DLL.
http://arcanecode.com/2007/02/14/more-oop-interfaces-in-c-part-2/