public void SerializeMessageBus() { var jsonDataContractSerializer = new JsonDataContractSerializer(); var callerContexts = new Stack <CallerContext>(); callerContexts.Push(new CallerContext { Identification = new Identification() { Id = "IdTest", Type = "TypeTest" } }); var messageBus = new MessageBus { Body = "Test", Header = { BodyType = "Un tipo de body cualquiera me vale.", CreatedAt = new DateTime(2010, 10, 10), CallStack = callerContexts } }; var serialize = jsonDataContractSerializer.Serialize(messageBus); var bytes = MessageBusParser.ToBytes(messageBus); var routerHeader = MessageBusParser.GetHeaderFromBytes(bytes); var message = MessageBusParser.GetMessageFromBytes(bytes); Assert.AreEqual(serialize, message); Assert.AreEqual("IdTest", routerHeader.Identification.Id); Assert.AreEqual("TypeTest", routerHeader.Identification.Type); }
/// <summary> /// Sends the specified MSG. /// </summary> /// <param name="message">The message.</param> /// <param name="priority">The priority.</param> /// <returns>Bytes Sent</returns> public override int Send(IMessage message, int priority) { try { var messageBus = MessageBusFactory.Create(_identification, message, DataContractSerializer); messageBus.Header.Priority = priority; var callerContext = CallerContextFactory.Create(_identification); messageBus.Header.CallStack.Push(callerContext); var serializedMessage = MessageBusParser.ToBytes(messageBus); SenderEndPoint.Send(serializedMessage, priority); InvokeSentMessage(messageBus.Header.BodyType, serializedMessage.Length); return(serializedMessage.Length); } catch (Exception ex) { Logger.Error("OutputGateway - Error Send Message", ex); throw; } }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="messageInfo">The message info.</param> /// <returns></returns> public override int Send(IMessage message, IMessageInfo messageInfo) { try { var messageBus = MessageBusFactory.Create(_identification, message, DataContractSerializer); messageBus.Header.Priority = messageInfo.Header.Priority; messageBus.Header.CallStack = messageInfo.Header.CallStack; messageBus.Header.CallContext = messageInfo.CurrentCallContext; if (!messageInfo.IsReply) { var callerContext = CallerContextFactory.Create(_identification, messageInfo.CurrentSession); messageBus.Header.CallStack.Push(callerContext); } else { messageBus.Header.Type = MessageBusType.Reply; } var serializedMessage = MessageBusParser.ToBytes(messageBus); if (!messageInfo.IsReply) { messageBus.Header.CallStack.Pop(); } SenderEndPoint.Send(serializedMessage, messageInfo.Header.Priority); InvokeSentMessage(messageBus.Header.BodyType, serializedMessage.Length); return(serializedMessage.Length); } catch (Exception ex) { Logger.Error("OutputGateway - Error Send Message", ex); throw; } }