private static void Handle(Header header, ZFrame bodyFrame) { //TODO - really we'd have a message handler factory: if (header.BodyType == typeof(SendFulfilmentCommand).Name) { var command = JsonConvert.DeserializeObject<SendFulfilmentCommand>(bodyFrame.ReadString()); var client = FulfilmentClientFactory.GetApiClient(command.FulfilmentType); try { client.Send(command.Address); Console.WriteLine("*** Sent fulfilment, type: {0}, to address: {1}", command.FulfilmentType, command.Address); } catch (Exception ex) { Console.WriteLine("*** Fulfilment failed, resending message"); var queueAddress = Config.Get("Queues.Fulfilment.Address"); header.HandledCount++; header.LastExceptionMessage = ex.Message; var messageFrames = new List<ZFrame>(); messageFrames.Add(new ZFrame(JsonConvert.SerializeObject(header))); messageFrames.Add(bodyFrame); using (var context = new ZContext()) using (var sender = new ZSocket(context, ZSocketType.PUSH)) { sender.Connect(queueAddress); sender.Send(new ZMessage(messageFrames)); } } } }
static void Console_WriteZFrame(string format, ZFrame frame, params object[] data) { var renderer = new StringBuilder(); var list = new List<object>(data); // here the renderer renderer.Append(format); renderer.Append(": "); renderer.Append("{"); renderer.Append(0 + data.Length); renderer.Append("}"); // now the message frame.Position = 0; if (frame.Length == 0) list.Add("0"); else list.Add(frame.ReadString()); frame.Position = 0; Console.WriteLine(renderer.ToString(), list.ToArray()); }