Somewhat related to: Is it possible for an NServiceBus endpoint to Handle and Publish using different serializers?
We already have wide deployment of NServiceBus in our infrastructure and it is all configured using the XmlSerializer
. However, a one-off situation has come up in which the XmlSerializer
is not going to meet our requirements, so I'm considering JsonSerializer
or BinarySerializer
.
Changing every single endpoint in the entire infrastructure to use a different serializer would be highly disruptive and time-wasting in terms of deployments, but I'm having trouble figuring out how to introduce one new endpoint that uses a different serializer... or rather, it's easy to configure the endpoint itself to use an alternate serializer, but I'm not sure how I can get any other endpoint to talk to it.
Am I stuck with one serializer type used throughout the entire architecture if I'm using NServiceBus 3.x? I seem to remember reading once, I think on the NServiceBus message boards, that serialization could be defined at the endpoint level, but there weren't many details given and the person who wrote that answer may have been overlooking the obvious interop issue above.
I want the architecture to look something like this:
+---------+ +------------+ (pub/sub) +------------+
| Web App |----->| Endpoint A |<--------->| Endpoint B |<-------> ...
+---------+ +------------+ +------------+
| (XML) (XML)
|
| +------------+
+---------->| Endpoint C |
+------------+
(JSON)
The problem is, of course, that although I can obviously configure Endpoint C to use the JsonSerializer
exclusively (and am OK with this), the "Web App" still needs to have its own (send-only) bus in order to talk to either Endpoint A or Endpoint C. And that bus has to be configured using one serializer. Since it already sends messages to a number of XmlSerializer
-based endpoints, I can't just switch it to JsonSerializer
. And there's no way that I've been able to find in the configuration or docs to direct NServiceBus to serialize some messages differently, either at the message level or at the endpoint level. I'm not even sure if the changes in NSB 4/5 are technically going to support this because they're all around how messages are received, not sent.
Is there a configuration method or setting somewhere that I'm missing that would allow me to do this? And if not, what other sensible options are there? Perhaps hosting two endpoints in the Web App? Or maybe a custom serializer that delegates to other serializers?