MassTransit does not invoke class with proper constructor parameter value

90 views
Skip to first unread message

rmanesiya747

unread,
Nov 19, 2015, 9:22:20 AM11/19/15
to masstransit-discuss
I am running into a rather strange issue. When I publish message  the constructor is initialized with proper GUID value, but when Breakpoint is invoked again when message arrives the value of GUID is always {00000000-0000-0000-0000-000000000000}. For some reason MassTransit is not invoking class with proper values. I verified the message on RabbitMQ subscription queue and the message indeed has the proper GUID value when it gets published.

    //Message
    public class OrderCreated 
    {
        private readonly Guid _aggregateId;

        public OrderCreated(Guid aggregatedId)
        {
            _aggregateId = aggregatedId;  //Breakpoint
        }

        public Guid AggregateId
        {
            get { return _aggregateId; }
        }
    }

    //Handler
    public class OrderCreatedEventHandler : IConsumer<OrderCreated>
    {

        public async Task Consume(ConsumeContext<OrderCreated> context)
        {
            await Task.Factory.StartNew(() =>
            {
                Console.WriteLine(context.Message.AggregateId);
            });
        }
    }
 
      //Portion of bus configuration code section
      cfg.ReceiveEndpoint(host,"my_consumer",
      c =>
      {
          c.Consumer<OrderCreatedEventHandler>();
      });

    //Left bus initialization code intentionally for clarity
    var _bus = _container.GetInstance<IBusControl>();
    _bus.Start();
    var order = new OrderCreated(Guid.NewGuid());
     _bus.Publish(order);
     _bus.Stop();



Chris Patterson

unread,
Nov 19, 2015, 9:32:27 AM11/19/15
to masstrans...@googlegroups.com
Your message needs to have a setter for the message property or the deserializer can't touch it. Add a setter (can be private) to the AggregateId property and you should be all set. 

__
Chris Patterson




--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/a875557f-ff4b-4051-95ae-96340b183fa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages