Question

I am trying to plug in #Rebus in an existing system landscape already using MSMQ to deliver messages.

Of course, the intent is to let Rebus take over everything ;-), but at the moment I am not able to change any existing code already working with MSMQ transport.

So, I thought I could just use Rebus in a new part of the system and send messages to existing app queues, but something goes wrong.

I configure my Rebus like this:

_bus = Configure.With(new WindsorContainerAdapter(container))
    .Logging(l => l.ColoredConsole(LogLevel.Debug))
    .Transport(t => t.UseMsmqInOneWayClientMode())
    .MessageOwnership(d => d.FromRebusConfigurationSection())
    .Serialization(s => s.UseBinarySerializer())
    .CreateBus().Start();

It sends the messages as planned, but when my existing app tries to read from the queue, an exception is thrown:

"Cannot deserialize the message passed as an argument. Cannot recognize the serialization format."

The method call in question is this:

// using System.Messaging.MessageQueue
receiveQueue.Receive(_queueTimeout, transaction);

Digging thru the code I can see that the DefaultFilter of Rebus is more or less like ours

https://github.com/rebus-org/Rebus/blob/1ab9b0a02883157de457e0b6106d289ace3a077e/src/Rebus.Snoop/Listeners/MsmqInteraction.cs#L567

return new MessagePropertyFilter
{
  Label = true,
  ArrivedTime = true,
  Extension = true,
  Body = true,
  Id = true,
  };

Our MessagePropertyFilter is configured like this:

var propertyFilter = new MessagePropertyFilter
{
    Id = true,
    Body = true,
    Label = true
};

Can this subtle change really be the cause of the exception? We also use the BinaryFormatter to serialize messages.

Any help would be greatly appreciated :-)

Was it helpful?

Solution

Rebus has its own message formatter, RebusTransportMessageFormatter, which is the thing that the MSMQ client delegates the actual reading/writing of the MSMQ Message to.

Check out the Read and Write methods in the formatter - they contain the logic that Rebus is using when using MSMQ to transfer messages, regardless of the chosen serializer.

If Rebus is to be used directly with an existing MSMQ solution, the existing solution must be capable of serializing/deserializing messages into the body the same way as Rebus does.

Note also how Rebus uses the Extension property to store headers - this probably means that you'll be unable to send a message from your existing MSMQ solution to Rebus, because Rebus will assume that there's an Extension stream of bytes that can be interpreted as an UTF7-encoded, serialized dictionary of header values.

Hope this helps :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top