private void Consumer_Received(object sender, BasicDeliverEventArgs e) { var body = Encoding.UTF8.GetString(e.Body); var payload = StandardPayload <T> .FromJSonString(body); this.OnReplyTo(payload); }
private void MonitorMessages(Subscription subscription) { int count = 0; while (this.IsConnected && this.RMQChannel.IsOpen) { BasicDeliverEventArgs bdea = default(BasicDeliverEventArgs); var gotMessage = subscription.Next(100, out bdea); if (gotMessage) { var msgText = string.Format("{0}{1}. {2} => {3}{0}", Environment.NewLine, ++count, bdea.Exchange, bdea.RoutingKey); //var msgText = string.Format("{3}. {0}: {1} -> '{2}'", bdea.Exchange, bdea.RoutingKey, Encoding.UTF8.GetString(bdea.Body), ++count); var print = SMQActorBase <T> .IsDebugMode; print = print && (!bdea.IsPing() || SMQActorBase <T> .ShowPings); if (print) { System.Console.WriteLine(msgText); } var body = Encoding.UTF8.GetString(bdea.Body); T payload = StandardPayload <T> .FromJSonString(body) as T; payload.DeliveryTag = bdea.DeliveryTag.SafeToString(); if (!String.IsNullOrEmpty(bdea.RoutingKey) && !bdea.RoutingKey.StartsWith("amq.")) { payload.RoutingKey = bdea.RoutingKey; } payload.ReplyTo = bdea.BasicProperties.ReplyTo; payload.Exchange = bdea.Exchange; this.OnMessageReceived(payload); try { this.CheckRouting(payload); } catch (Exception ex) { payload.Exception = ex; } this.OnAfterMessageReceived(payload); } } }