Search code examples
c#.netrabbitmqrebusrebus-rabbitmq

Can't receive rebus rabbitMQ messages when the object which is published is not shared


When trying to solve my issue with not receiving messages through RabbitMQ using Rebus, I tried playing with this sample: https://github.com/rebus-org/RebusSamples/tree/master/PubSubNative and found that the object, which is published from the publisher(pub) to the subscribers(subs), have to be the exact same shared object "StringMessage" for both subs and pub. It does not work when I create classes by the same name and properties in each project. I like it to not have the shared files but have their own classes - if it's possible?


Solution

  • Yes it's possible, but you'll have to circumvent the deserialization on the receiving end to somehow resolve the receiver's definition of StringMessage even though it's the sender's StringMessage that got serialized.

    You might want to check out the SharedNothing sample that demonstrates this particular thing.

    The main part is the CustomMessageDeserializer that uses this dictionary to map from simple, assembly-qualified type names to the desired types.