Exemplo n.º 1
0
        public void Process(EasyBus.Contracts.IMessageHandler handler, IMessage <string> msg)
        {
            var messsageType = handler.GetType().BaseType.GetGenericArguments().First();
            var payload      = JsonConvert.DeserializeObject(msg.Body, messsageType) as EasyBus.Contracts.IMessage;

            payload.CorrelationId = msg.Properties.CorrelationId;

            handler.Handle(payload);
        }
Exemplo n.º 2
0
        public void Subscribe(EasyBus.Contracts.IMessageHandler handler)
        {
            bus = container.GetInstance <IRabbitBus>().Bus;
            // Get queue name.
            var queueName = handler.QueueName;
            var queue     = bus.Advanced.QueueDeclare(queueName);

            bus.Advanced.Consume <string>(queue, (msg, info) =>
            {
                try
                {
                    Process(handler, msg);
                }
                catch (Exception exc)
                {
                    HandleConsumerError(queue, exc);
                }
            });
        }