2
votes

I got a producer (third party) publishing messages on ActiveMQ which are basically serialized POCO objects. Currently I consume those using infrastructure provided by https://www.nuget.org/packages/Apache.NMS.ActiveMQ/ with simple plumbing to support strongly typed messages looking almost like

public async void OnMessage(IMessage message)
{
     var msgBody = ((ITextMessage)message).Text;
     var deserialized = JsonConvert.DeserializeObject<T>(msgBody);
     await Handler.Handle(deserialized);
     message.Acknowledge();
}

Producer and consumer do not share the binaries with contracts, type T are my own model classes mimicking the POCO used by producer. It is very simplistic but works for basic scenarios.

I tried switching to MassTransit but no matter the consumer config I use it seems like it is unable to handle deserialization of such messages. It fails with exception

Error converting value "ID:{cluster_name}-0f5e525f2f14ad485-38017-1539583126655-8:18:1:1:2" to type 'System.Nullable`1[System.Guid]'. Path ''.

{cluster-name} being the name of ActiveMQ cluster.

I read on http://masstransit-project.com/MassTransit/advanced/interoperability.html that MassTransit requires messages to involve a set of metadata properties. The messages I'm trying to consume don't have such properties as they are coming from third party not having a clue I'm trying to use MassTransit.

Question: Is it possible to handle such messages with MassTransit? I cannot force the publisher to adjust message schema.

1
You can write your own message deserializer to handle the format and then use the built-in MassTransit serializer to send/publish messages to other parts of the system (which can use standard off-the-shelf MassTransit).Chris Patterson
@ChrisPatterson Thanks, I'll give it a try.codhri

1 Answers

0
votes

The best solution is to consume messages from the third-party using the ActiveMQ client, convert them to messages that you will be working on within MassTransit-powered environment and republish those converted messages. It will be your gateway, a lightweight stateless service. All other message consumer down the pipeline will then be able to use MassTransit.