复杂消息和公共交通反序列化
我在 MT 中发布一条消息,其中包含多个对象类型属性,因为我在编译时不知道类型。当我在消费者中收到消息时,我看到对象类型的属性是用 Newtonsoft JObject 实例填充的。 JObject 类驻留在 Masstransit.dll 的 ILMerged Newtonsoft.Json 程序集中。该程序集中的 JObject-Class 被标记为内部。每当我尝试将属性值转换为 Newtonsoft.Json 的 Nuget-Assembly 提供的 JObject 时,它都会失败。
所以我的问题是:
- 将属性值转换为 JObject 的正确方法是什么?
- 选角为何失败?也就是说,clr在这里遇到的困难是什么?
- 我可以在我的消费者中获取原始的、未序列化的消息正文吗?
谢谢。
I publish a message in MT which has several Object-typed properties, as I don't know the type at compile time. When I receive the message in the consumer I see, that the Object-typed properties are populated with Newtonsoft JObject-instances. The JObject-Class resides in the ILMerged Newtonsoft.Json-assembly in Masstransit.dll. The JObject-Class in this assembly is marked internal. Whenever I try to cast the property-value to an JObject provided by a Nuget-Assembly of Newtonsoft.Json it fails.
So my questions are:
- What is the correct way to cast the property-value to JObject?
- Why does the cast fail? That means, what are the difficulties the clr has here?
- Can I get the raw, unserialized message-body in my consumer?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在任何消息协定上进行运行时输入,则无法使用 JSON 序列化。如果您想执行此操作,则需要使用二进制序列化器。
您无法访问原始的、未序列化的消息正文;如果消息无法反序列化,则不会调用任何用户代码。
将任何类型标记为内部将不允许我们反序列化消息。无法调用构造函数,因此无法创建对象。我不确定二进制序列化器是否允许您绕过这个限制,这不是我测试过的。
如果您还有其他问题,也欢迎您加入邮件列表,https ://groups.google.com/forum/#!forum/masstransit-discuss。
You cannot use JSON serialization if you are doing runtime typing on any message contracts. If you want to do this, you'll require the use of the binary serializer.
You cannot access the raw, unserialized message-body; if the message cannot be deserialized, then no user code is called.
Having any types marked internal will not allow us to deserialize the message. A constructor cannot be called, thus no object creation. I'm not sure the binary serializer will allow you to get around this limitation, not something I've tested.
If you have other questions, you're welcomed to join the mailing list as well, https://groups.google.com/forum/#!forum/masstransit-discuss.
作为 MassTransit 的创建者之一,如果您将 包含
在您的消息合同中,那么您就做错了。利用框架的强类型发布功能,而不是在 MT 内的发布/订阅系统已经完成的调度之上进行自己的动态调度。
As one of the creators of MassTransit, if you're including
In your message contract, you're doing it wrong. Leverage the strongly typed publishing features of the framework instead of doing your own dynamic dispatch on top of the dispatching already being done by the publish/subscribe system inside MT.
我的上述问题可能只是由于对我的消息系统的误解而引起的。但我发现了一个令人讨厌的解决方法,将嵌套的 JObject 转换为正确的域对象:
My above described problem probably arose just out of a misconception of my messaging system. But I found a nasty workaround to convert the nested JObjects to the right domain objects: