1

I have started to learn masstransit. Below is a simple example

public class YourMessage { public string Text { get; set; } }
public class Program
{
    public static void Main()
    {
        Bus.Initialize(sbc =>
        {
            sbc.UseMsmq();
            sbc.VerifyMsmqConfiguration();
            sbc.UseMulticastSubscriptionClient();
            sbc.ReceiveFrom("msmq://localhost/test_queue");
            sbc.Subscribe(subs=>
            {
                subs.Handler<YourMessage>(msg=>Console.WriteLine(msg.Text));
            });
        });

        Bus.Instance.Publish(new YourMessage{Text = "Hi"});
    }
}

As we see above while subscribe the message from Queue i should use CLASS (here it is "YourMessage"). But my question is, Is there any way to read the message with out specifying the class? meaning using Dynamic something like that.

The problem is when i write a simple pub-sub client i can read the message using Dynamic from my Queue (RabbitMQ here).

here is my classic subscriber

 while (isConsuming)
            {
                try
                {
                    if (!mqchannel.IsOpen)
                        throw new Exception("Channel is closed");

                    BasicDeliverEventArgs e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                    IBasicProperties props = e.BasicProperties;

                    //Adds the message to Event Listener
                    onMessageReceived(rabbitMqHelper.DecodeMessage((e == null || e.Body == null) ? null : e.Body));

                    //Acknowledge receipt of messages to Queue
                    mqchannel.BasicAck(e.DeliveryTag, false);
                }

How can i achieve above using masstransit ?

1 Answer 1

2

Bottom line is no, you can't subscribe to a dynamic type meaningfully with MassTransit. This isn't a behaviour I expect we will support.

Generally, messages are static contracts between and the only things serialized into the consuming object is those properties identified in the subscribing type.

If that's all you need, you could consider using EasyNetQ, it might support doing that. We do not suggest you head down this path, as it's fraught with peril. From experience, having as little surprise in payload as possible makes for a much better life supporting systems.

1
  • So, I should use the class type :) sure and thank you so much for your input
    – backtrack
    May 7, 2015 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.