public void ProcessReceivedMessageInputValidMessageAssertValid() { var jsonDataContractSerializer = new JsonDataContractSerializer(); var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date }; var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer); var inputGateway = AgentGatewayFactory.CreateInputGateway <IMessage>(_receiverEndPoint.Object, 5); var eventargs = new EventReceiverEndPointHandlerArgs { Message = Encoding.UTF8.GetBytes(jsonDataContractSerializer.Serialize(messageBus)) }; _receiverEndPoint.Setup(r => r.Start()).Raises(r => r.OnReceivedMessage += null, new object[] { null, eventargs }); IMessage messageReceived = null; inputGateway.OnMessage += (sender, args) => messageReceived = args.Message; inputGateway.Start(); Assert.AreEqual(messageFake.CreatedAt, ((IMessageFake)messageReceived).CreatedAt); }
public void ProcessReceivedMessageInputValidMessageAssertValid() { var jsonDataContractSerializer = new JsonDataContractSerializer(); var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date }; var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer); var inputGateway = RouterGatewayFactory.CreateInputGateway(_receiverEndPoint.Object, 5); var eventargs = new EventReceiverEndPointHandlerArgs { Message = Encoding.UTF8.GetBytes(jsonDataContractSerializer.Serialize(messageBus)) }; _receiverEndPoint.Setup(r => r.Start()).Raises(r => r.OnReceivedMessage += null, new object[] { null, eventargs }); MessageBus messageReceived = null; inputGateway.OnMessage += (sender, args) => messageReceived = jsonDataContractSerializer.Deserialize <MessageBus>(args.Message); inputGateway.Start(); Assert.AreEqual(messageBus.Body, messageReceived.Body); Assert.AreEqual(messageBus.Header.Type, messageReceived.Header.Type); Assert.AreEqual(messageBus.Header.BodyType, messageReceived.Header.BodyType); }
/// <summary> /// Reinjects the specified message. /// </summary> /// <param name="message">The message.</param> /// <param name="header">The header.</param> public void Reinject(IMessage message, MessageHeader header) { if (header.ReinjectionNumber > _maxReijections) { return; } header.ReinjectionNumber++; var messageBus = MessageBusFactory.Create(header.IdentificationService, message, DataContractSerializer); messageBus.Header = header; var serializedMessage = DataContractSerializer.Serialize(messageBus); _receiverReceiverEndPoint.Reinject(serializedMessage, header.Priority); }
public void SendMessageAssertTrue() { var jsonDataContractSerializer = new JsonDataContractSerializer(); var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date }; var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer); var message = string.Empty; _senderEndPoint.Setup(s => s.Send(It.IsAny <string>(), It.IsAny <int>())).Callback <string, int>((s, p) => message = s); var outputGateway = RouterGatewayFactory.CreateOutputGateway(_senderEndPoint.Object); var serialize = jsonDataContractSerializer.Serialize(messageBus); outputGateway.Send(Encoding.UTF8.GetBytes(serialize)); Assert.AreEqual(serialize, message); }
/// <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; } }
public void SendMessageAssertTrue() { var jsonDataContractSerializer = new JsonDataContractSerializer(); var messageFake = new MessageFake { CreatedAt = DateTime.Now.Date }; var messageBus = MessageBusFactory.Create(new Identification(), messageFake, jsonDataContractSerializer); var message = string.Empty; _senderEndPoint.Setup(s => s.Send(It.IsAny <string>(), It.IsAny <int>())).Callback <string, int>((s, p) => message = s); var outputGateway = AgentGatewayFactory.CreateOutputGateway(_identification, _senderEndPoint.Object); outputGateway.Send(messageFake); var deserialized = jsonDataContractSerializer.Deserialize <MessageBus>(message); Assert.AreEqual(messageBus.Body, deserialized.Body); Assert.AreEqual(messageBus.Header.Type, deserialized.Header.Type); Assert.AreEqual(messageBus.Header.BodyType, deserialized.Header.BodyType); }
/// <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; } }