Ejemplo n.º 1
0
 public bool Send(Message message)
 {
     return Send(_writer =>
     {
         Reporter.Output.WriteLine($"OnSend ({message})");
         _writer.Write(JsonConvert.SerializeObject(message));
     });
 }
Ejemplo n.º 2
0
 public bool Send(Message message)
 {
     return Send(_writer =>
     {
         _log.LogInformation($"Send ({message})");
         _writer.Write(JsonConvert.SerializeObject(message));
     });
 }
Ejemplo n.º 3
0
        public void Negotiate(Message message)
        {
            if (!IsProtocolNegotiation(message))
            {
                return;
            }

            Reporter.Output.WriteLine("Initializing the protocol negotiation.");

            if (EnvironmentOverridden)
            {
                Reporter.Output.WriteLine($"DTH protocol negotiation is override by environment variable {EnvDthProtocol} and set to {CurrentVersion}.");
                return;
            }

            var tokenValue = message.Payload?["Version"];
            if (tokenValue == null)
            {
                Reporter.Output.WriteLine("Protocol negotiation failed. Version property is missing in payload.");
                return;
            }

            var preferredVersion = tokenValue.ToObject<int>();
            if (preferredVersion == 0)
            {
                // the preferred version can't be zero. either property is missing or the the payload is corrupted.
                Reporter.Output.WriteLine("Protocol negotiation failed. Protocol version 0 is invalid.");
                return;
            }

            CurrentVersion = Math.Min(preferredVersion, MaxVersion);
            Reporter.Output.WriteLine($"Protocol negotiation successed. Use protocol {CurrentVersion}");

            if (message.Sender != null)
            {
                Reporter.Output.WriteLine("Respond to protocol negotiation.");
                message.Sender.Transmit(Message.FromPayload(
                    MessageTypes.ProtocolVersion,
                    0,
                    new { Version = CurrentVersion }));
            }
            else
            {
                Reporter.Output.WriteLine($"{nameof(Message.Sender)} is null.");
            }
        }
Ejemplo n.º 4
0
 public bool IsProtocolNegotiation(Message message)
 {
     return message?.MessageType == MessageTypes.ProtocolVersion;
 }
Ejemplo n.º 5
0
 public bool Transmit(Message message)
 {
     message.HostId = _hostName;
     return _queue.Send(message);
 }