protected override async Task Send(List <IMessage> toSend)
        {
            // serialize payload

            MemoryStream stream = new MemoryStream();

            using (var binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream))
            {
                payloadSerializer.WriteObject(binaryDictionaryWriter, toSend);
                stream.Flush();
            }

            var now = DateTime.UtcNow;

            // send message

            var message = new ProcessMessage()
            {
                DeploymentTimestamp = deploymentTimestamp,
                Source    = destination,
                LastClock = null,
                Payload   = stream.ToArray()
            };

            var messageBytes = ProcessMessage.Serialize(message);

            await sender.SendAsync(new EventData(messageBytes));

            logger.LogTrace($"{DateTime.UtcNow:o} Sent {message}->{destination} ({messageBytes.Length / 1024}kB)");
        }
Beispiel #2
0
        protected override async Task Send(List <IMessage> toSend)
        {
            // serialize payload

            MemoryStream stream = new MemoryStream();

            using (var binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream))
            {
                payloadSerializer.WriteObject(binaryDictionaryWriter, toSend);
                stream.Flush();
            }

            var now = DateTime.UtcNow;

            // send message

            var message = new ProcessMessage()
            {
                DeploymentTimestamp = default(DateTime),
                Source    = processId,
                LastClock = null,
                Payload   = stream.ToArray()
            };

            var messageBytes = ProcessMessage.Serialize(message);

            await sender.SendAsync(new EventData(messageBytes));

            logger.LogTrace($"{DateTime.UtcNow:o} Sent {message}->{destination} ({messageBytes.Length / 1024}kB)");

            if (lastSendOrDoorbell + configuration.ReceiveWaitTime < now)
            {
                // send doorbell message
                var doorbellMessage = new DoorbellMessage()
                {
                    ProcessId = destination,
                    Guid      = Guid.NewGuid()
                };
                var doorbell = connections.GetDoorbellSender(destination);
                await doorbell.SendAsync(new EventData(DoorbellMessage.Serialize(doorbellMessage)));

                logger.LogTrace($"{DateTime.UtcNow:o} Sent {doorbellMessage}");
            }

            lastSendOrDoorbell = now;
        }