Example #1
0
        public Task Send(ArraySegment <byte> data, params object[] connectionIDs)
        {
            var task = new Task(() =>
            {
                var msg = new NetMQMessage();
                if (_socket is RouterSocket)
                {
                    msg.Append(new byte[0]);
                    msg.AppendEmptyFrame();
                }
                msg.Append(data.Count == data.Array.Length ? data.Array : data.ToArray());

                if (connectionIDs.Length <= 0)
                {
                    _socket.SendMultipartMessage(msg);
                }
                else
                {
                    foreach (var connection in connectionIDs)
                    {
                        if (_socket is RouterSocket && connection is byte[])
                        {
                            msg.Pop();
                            msg.Push(((byte[])connection));
                        }
                        _socket.SendMultipartMessage(msg);
                    }
                }
            });

            task.Start(_scheduler);
            return(task);
        }
Example #2
0
    public bool sendAndReceive(ref NetMQMessage req_msg, ref NetMQ.Msg resp_msg)
    {
        if (socket == null)
        {
            reconnect();
        }

        bool         ok   = false;
        NetMQMessage copy = new NetMQMessage(req_msg);

        socket.SendMultipartMessage(copy);

        // receive
        if (socket.TryReceive(ref resp_msg, timeout))
        {
            ok = true;
            //UnityEngine.Debug.Log("ReliableExternalClient: response received "
            //    + new StdMessage(resp_msg.Data[1], resp_msg.Data[2]).to_string());
        }

        copy.Clear();
        socket.Dispose();
        socket.Close();
        socket = null;
        if (socket == null)
        {
            UnityEngine.Debug.Log("ReliableExternalClient: socket closed and null");
        }

        return(ok);
    }
Example #3
0
        /// <summary>
        /// Send a message to broker
        /// if no message provided create a new empty one
        /// prepend the message with the MDP prologue
        /// </summary>
        /// <param name="mdpCommand">MDP command</param>
        /// <param name="data">data to be sent</param>
        /// <param name="message">the message to send</param>
        private void Send(MDPCommand mdpCommand, string data, NetMQMessage message)
        {
            // cmd, null, message      -> [REPLY],<null>,[client adr][e][reply]
            // cmd, string, null       -> [READY],[service name]
            // cmd, null, null         -> [HEARTBEAT]
            var msg = ReferenceEquals(message, null) ? new NetMQMessage() : message;

            // protocol envelope according to MDP
            // last frame is the data if available
            if (!ReferenceEquals(data, null))
            {
                // data could be multiple whitespaces or even empty(!)
                msg.Push(data);
            }
            // set MDP command                          ([client adr][e][reply] OR [service]) => [data]
            msg.Push(new[] { (byte)mdpCommand });       // [command][header][data]
            // set MDP Header
            msg.Push(m_mdpWorker);                      // [header][data]
            // set MDP empty frame as separator
            msg.Push(NetMQFrame.Empty);                 // [e][command][header][data]

            //Log ($"[WORKER] sending msg to broker / Command {mdpCommand}");

            m_worker.SendMultipartMessage(msg);
        }
Example #4
0
        public static void SendError(byte[] destination, NetMQSocket socket, ErrorCode errorCode)
        {
            var response = ResponseCreator.Create(new NoEncryption(), destination, MessageType.Error,
                                                  JsonConvert.SerializeObject(errorCode));

            socket.SendMultipartMessage(response);
        }
Example #5
0
        /// <summary>
        ///     send a request to a broker for a specific service and receive the reply
        ///
        ///     if the reply is not available within a specified time
        ///     the client deems the connection as lost and reconnects
        ///     for a specified number of times. if no reply is available
        ///     throughout this procedure the client abandons
        ///     the reply is checked for validity and returns the reply
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <returns>the reply from service</returns>
        /// <exception cref="ApplicationException">malformed message received</exception>
        /// <exception cref="ApplicationException">malformed header received</exception>
        /// <exception cref="ApplicationException">reply received from wrong service</exception>
        public NetMQMessage Send(string serviceName, NetMQMessage request)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ApplicationException("serviceName must not be empty or null.");
            }

            if (ReferenceEquals(request, null))
            {
                throw new ApplicationException("the request must not be null");
            }
            // memorize it for the event handler
            m_serviceName = serviceName;

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
            {
                Connect();
            }

            var message = new NetMQMessage(request);

            // prefix the request according to MDP specs
            // Frame 1: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 2: service name as printable string
            // Frame 3: request
            message.Push(serviceName);
            message.Push(m_mdpClient);

            Log(string.Format("[CLIENT INFO] sending {0} to service {1}", message, serviceName));

            var retiesLeft = Retries;

            while (retiesLeft > 0)
            {
                // beware of an exception if broker has not picked up the message at all
                // because one can not send multiple times! it is strict REQ -> REP -> REQ ...
                m_client.SendMultipartMessage(message);

                // Poll -> see ReceiveReady for event handling
                if (m_client.Poll(Timeout))
                {
                    // set by event handler
                    return(m_reply);
                }
                // if it failed assume communication dead and re-connect
                if (--retiesLeft > 0)
                {
                    Log("[CLIENT WARNING] no reply, reconnecting ...");

                    Connect();
                }
            }

            Log("[CLIENT ERROR] permanent error, abandoning!");

            m_client.Dispose();

            return(null);
        }
        public override void Response(TResponse response)
        {
            try
            {
                #region Sending Response
                // Preparing response.
                var messageToClient = new NetMQMessage();
                messageToClient.Append(clientAddress);
                messageToClient.AppendEmptyFrame();
                messageToClient.Append(MessageQueueCommonItems.SerializeToJson(response));

                // Sending response.
                responseChannel.SendMultipartMessage(messageToClient);
                #endregion
            }
            catch (QueueException queueException)
            {
                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          errorCode: QueueErrorCode.FailedToSendResponseMessage,
                          message: ErrorMessages.FailedToSendResponseMessage,
                          innerException: ex,
                          queueContext: CommonItems.ZeroMqName,
                          logger: logger);
            }
        }
 public void Start()
 {
     while (true)
     {
         var msg = frontend.ReceiveMultipartMessage();
         backend.SendMultipartMessage(msg);
         frontend.SendFrame("Success");
     }
 }
Example #8
0
        /// <summary>
        /// Sends an object to the Server
        /// </summary>
        /// <typeparam name="T">Type of object to be sent</typeparam>
        /// <param name="objectToSend">The object to send to the server</param>
        public void Send <T>(T objectToSend)
        {
            byte[]       data            = BsonMagic.SerializeObject <T>(objectToSend);
            NetMQMessage messageToServer = new NetMQMessage();

            messageToServer.AppendEmptyFrame();
            messageToServer.Append(typeof(T).AssemblyQualifiedName);
            messageToServer.Append(data);

            clientSocket.SendMultipartMessage(messageToServer);
        }
        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<QueryEventsForStreamResponse>) pendingRequest;
            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.QueryEventsByStream);
            msg.Append(requestId.ToByteArray());
            msg.Append(_context);
            msg.Append(_stream);
            msg.Append(_fromVersion.ToNetMqFrame());
            msg.Append(_maxVersion.ToNetMqFrame());

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.QueryEventsByStreamResponse)
                    pending.SetException(new UnsupportedCommandException(command));

                var count = m.PopInt32();

                var events = new EventInStorage[count];

                for (var i = 0; i < count; i++)
                {
                    var id = new Guid(m.Pop().ToByteArray());
                    var streamId = m.Pop().ConvertToString();
                    var context = m.Pop().ConvertToString();
                    var sequence = m.PopInt64();
                    var timestamp = m.PopDateTime();;
                    var type = m.PopString();
                    var headers = m.PopStringOrNull();
                    var body = m.PopString();

                    events[i] = new EventInStorage(context, streamId, sequence, type, id, headers, body, timestamp);
                }

                var result = new QueryEventsForStreamResponse(_context, _stream, events);
                pending.SetResult(result);
            };
        }
Example #10
0
        /// <summary>
        /// Send an object to a specified client
        /// </summary>
        /// <typeparam name="T">The type of the object being sent</typeparam>
        /// <param name="objectToSend">The object to send to the client</param>
        /// <param name="clientId">ID of the client to whom the object will be sent</param>
        public void Send <T>(T objectToSend, Guid clientId)
        {
            byte[] data = BsonMagic.SerializeObject <T>(objectToSend);

            NetMQMessage msgToSend = new NetMQMessage();

            msgToSend.Append(clientId.ToByteArray());
            msgToSend.AppendEmptyFrame();
            msgToSend.Append(typeof(T).AssemblyQualifiedName);
            msgToSend.Append(data);

            netMqSocket.SendMultipartMessage(msgToSend);
        }
        private void ProcessMessage(object sender, NetMQSocketEventArgs eventArgs)
        {
            try
            {
                NetMQMessage raw     = eventArgs.Socket.ReceiveMultipartMessage();
                NetMQSocket  client  = eventArgs.Socket;
                Message      message = Message.Parse(raw);
                Message      reply   = null;
                switch (message)
                {
                case GetBlock getBlock:
                    var block   = _chain[getBlock.BlockHash];
                    var payload = block.Serialize();
                    reply = new Block(payload);
                    break;

                case GetTip getTip:
                    var tip = _chain.Tip;
                    reply = new Tip(tip.Index, tip.Hash);
                    break;

                case GetState getState:
                    var state = _chain.GetState(
                        getState.Address,
                        getState.BlockHash) ?? default(Null);
                    var codec = new Codec();
                    reply = new State(codec.Encode(state));
                    break;

                case GetBlockHash getBlockHash:
                    var blockHash = _chain[getBlockHash.BlockIndex].Hash;
                    reply = new BlockHash(blockHash);
                    break;

                default:
                    throw new InvalidMessageException(
                              $"Unhandled message [type: {message.GetType()}].");
                }

                client.SendMultipartMessage(reply.ToNetMQMessage());
            }
            catch (Exception e)
            {
                Log.Error("Error occurred.", e);
            }
        }
        public void ProcessMessage(NetMQMessage message, NetMQSocket socket)
        {
            var sender = new List<NetMQFrame>(message.FrameCount);

            for (int i = 0; i < message.FrameCount; i++)
            {
                var frame = message[i];
                if (frame.BufferSize == 0)
                    break;

                sender.Add(frame);
            }

            var protocolFrame = message[sender.Count + 1];
            var commandFrame = message[sender.Count + 2];
            var requestId = message[sender.Count + 3];

            try
            {
                _processor.ProcessMessage(message, socket);
            }
            catch (Exception e)
            {
                Log.Warn("[EHMessageProcessor] Error processing message.", e);
                var entry = _errorResolver.GetError(e);

                if (entry != null)
                {
                    var msg = new NetMQMessage();

                    foreach (var frame in sender)
                    {
                        msg.Append(frame);
                    }

                    msg.AppendEmptyFrame();

                    msg.Append(protocolFrame);
                    msg.Append(requestId);
                    msg.Append(ResCommands.Error);
                    msg.Append(entry.ErrorCode.ToString(CultureInfo.InvariantCulture));
                    msg.Append(entry.Message);
                    socket.SendMultipartMessage(msg);
                }
            }
        }
Example #13
0
        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<CommitResponse>) pendingRequest;

            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.AppendCommit);
            msg.Append(requestId.ToByteArray());
            msg.Append(Context);
            msg.Append(Stream);
            msg.Append(ExpectedVersion.ToNetMqFrame());
            msg.Append(Events.Length.ToNetMqFrame());

            foreach (var e in Events)
            {
                msg.Append(e.EventId.ToByteArray());
                msg.Append(e.Timestamp.ToNetMqFrame());
                msg.Append(e.TypeTag);
                msg.Append(e.Headers.ToNetMqFrame());
                msg.Append(e.Body);
            }

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.CommitResult)
                    pending.SetException(new UnsupportedCommandException(command));

                var commitId = new Guid(m.Pop().ToByteArray());
                var result = new CommitResponse(commitId);
                pending.SetResult(result);
            };
        }
        protected override Task SendAsync(WampMessage <object> message)
        {
            var task = new Task(() =>
            {
                var msg = new NetMQMessage();
                if (_socket is RouterSocket)
                {
                    msg.Append(new byte[0]);
                    msg.AppendEmptyFrame();
                }

                var bytes = _binding.Format(message);
                msg.Append(bytes);
                _socket.SendMultipartMessage(msg);
            });

            task.Start(_scheduler);
            return(task);
        }
Example #15
0
        public void Send(NetMQSocket socket)
        {
            var msg = new NetMQMessage();
            msg.Append(_context.Sender);
            msg.AppendEmptyFrame();
            msg.Append(_protocol);
            msg.Append(_context.RequestId);

            if (_error == null)
            {
                msg.Append(ResCommands.CommitResult);
                msg.Append(_context.CommitId.ToByteArray());
            }
            else
            {
                msg.Append(ResCommands.Error);
                msg.Append(_error.ErrorCode.ToString(CultureInfo.InvariantCulture));
                msg.Append(_error.Message);
            }

            socket.SendMultipartMessage(msg);
        }
Example #16
0
        /// <summary>
        ///     send a asyncronous request to a broker for a specific service without receiving a reply
        ///
        ///     there is no retry logic
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <exception cref="ApplicationException">serviceName must not be empty or null.</exception>
        /// <exception cref="ApplicationException">the request must not be null</exception>
        public void Send([NotNull] string serviceName, NetMQMessage request)
        {
            // TODO criar tabela de pedidos ongoing

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ApplicationException("serviceName must not be empty or null.");
            }

            if (ReferenceEquals(request, null))
            {
                throw new ApplicationException("the request must not be null");
            }

            // memorize it for the event handler
            m_serviceName = serviceName;

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
            {
                Connect();
            }

            var message = new NetMQMessage(request);

            // prefix the request according to MDP specs
            // Frame 1: Empty Frame, because DEALER socket needs to emulate a REQUEST socket to comunicate with ROUTER socket
            // Frame 2: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 3: service name as printable string
            // Frame 4: request
            message.Push(serviceName);
            message.Push(m_mdpClient);
            message.PushEmptyFrame();

            Log($"[CLIENT INFO] sending message to service {serviceName}");

            m_client.SendMultipartMessage(message); // Or TrySend!? ErrorHandling!?
        }
Example #17
0
        public Task <OperateResult> SendAsync(TransportMessage message)
        {
            NetMQSocket channel = null;

            try
            {
                channel = _connectionChannelPool.Rent();
                NetMQMessage msg = new NetMQMessage();
                msg.Append(message.GetName());
                msg.Append(System.Text.Json.JsonSerializer.Serialize(message.Headers.ToDictionary(x => x.Key, x => (object)x.Value)));
                msg.Append(message.Body);
                channel.SendMultipartMessage(msg);
                _logger.LogDebug($"ZeroMQ topic message [{message.GetName()}] has been published.");
                return(Task.FromResult(OperateResult.Success));
            }
            catch (Exception ex)
            {
                var wrapperEx = new PublisherSentFailedException(ex.Message, ex);
                var errors    = new OperateError
                {
                    Code        = ex.HResult.ToString(),
                    Description = ex.Message
                };

                return(Task.FromResult(OperateResult.Failed(wrapperEx, errors)));
            }
            finally
            {
                if (channel != null)
                {
                    var returned = _connectionChannelPool.Return(channel);
                    if (!returned)
                    {
                        channel.Dispose();
                    }
                }
            }
        }
Example #18
0
        public void sendMessage(NetMQSocket socket, KernelMessage envelope, string messageType, object content)
        {
            var header = createHeader(messageType, envelope);
            var msg    = new NetMQMessage();

            foreach (var ident in envelope.Identifiers)
            {
                msg.Append(ident);
            }

            var _header        = serialize(header);
            var _parent_header = serialize(envelope.Header);
            var _meta          = "{}";
            var _content       = serialize(content);
            var _signature     = sign(new string[] { _header, _parent_header, _meta, _content });

            msg.Append(encode("<IDS|MSG>"));
            msg.Append(encode(_signature));
            msg.Append(encode(_header));
            msg.Append(encode(_parent_header));
            msg.Append(encode(_meta));
            msg.Append(encode(_content));
            socket.SendMultipartMessage(msg);
        }
        private void RouterSocket_ReceiveReady(object sender, NetMQSocketEventArgs e)
        {
            NetMQMessage message = e.Socket.ReceiveMultipartMessage();

            _dealerSocket.SendMultipartMessage(message);
        }
 public void Send(NetMQSocket socket)
 {
     socket.SendMultipartMessage(_msg);
 }
Example #21
0
        /// <summary>
        ///     New non blocking queue, using Thread events for smart control.
        /// </summary>
        private void MessageSenderLoop()
        {
            _logger.Debug("Starting dequeue loop...");
            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "Nyx Borg Message Queue";
            }
            Thread.CurrentThread.Priority = ThreadPriority.Highest;
            while (!_messageLoopToken.IsCancellationRequested)
            {
                if (_messageQueue.Count == 0)
                {
                    _messageSendResetEvent.WaitOne();
                }
                else if (!_isConnected)
                {
                    if (_messageLoopCancelation.IsCancellationRequested)
                    {
                        _messageReplyReceived.OnError(new EndOfStreamException("Message queue is stopping."));
                    }
                    _messageLoopToken.ThrowIfCancellationRequested();
                    _messageSendResetEvent.WaitOne(TimeSpan.FromSeconds(_timeOut));
                    continue;
                }
                // Check if we have messages or if our hub is alive
                if (_messageQueue.Count == 0)
                {
                    continue;
                }
                if (_reqSocket == null)
                {
                    continue;
                }
                // Dequeues message if dequeue on fail is on, else leave this to a later stage
                var           dequeueOnFail = _dequeueOnFail;
                MessageHelper msg;
                lock (MessageQueueSync) msg = dequeueOnFail ? _messageQueue.Dequeue() : _messageQueue.Peek();

                var readonlyMsg = msg.Message.AsReadOnly();
                _logger.Trace("{0} message {1}", dequeueOnFail ? "Dequeued" : "Peeked", msg.Message);
                var abort = FilterMessage(msg.Message);
                if (abort)
                {
                    _logger.Debug("Message {0} was not sent.", msg.Message);
                    if (!dequeueOnFail || msg.Retries > _maxFailedRetries)
                    {
                        lock (MessageQueueSync) _messageQueue.Dequeue();
                    }
                    else
                    {
                        msg.Retries++;
                    }
                    if (_messageQueue.Count == 0)
                    {
                        _messageSendResetEvent.Reset();
                    }
                    continue;
                }

                // Reply control
                NetMQMessage mqMessage = null;
                var          retries   = _timeOutRetries;
                var          timeout   = Debugger.IsAttached ? 120000 : _timeOut;
                try
                {
                    _reqSocket.SendMultipartMessage(msg.Message.ToNetMQMessage());
                    var received = false;
                    while (!received && retries > 0)
                    {
                        received = _reqSocket.TryReceiveMultipartMessage(TimeSpan.FromMilliseconds(timeout), ref mqMessage);
                        retries--;
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Error sending message. REQ-REP Socket state problem.", ex);
                }

                if (mqMessage == null)
                {
                    _logger.Error("Message with id={0}, failed, due to timeout of {1}ms reached, hub maybe busy.", msg.Message.ShortId(), timeout * retries);
                    NotifyMessageFailedOut(readonlyMsg, "No reply or invalid data return by the hub.");
                    // Here we restart all over again...
                    if (!dequeueOnFail && msg.Retries <= _maxFailedRetries)
                    {
                        _logger.Debug("Requeue message with id={0}.", msg.Message.ShortId());
                        msg.Retries++;
                    }
                    else if (msg.Retries > _maxFailedRetries)
                    {
                        if (!dequeueOnFail)
                        {
                            lock (MessageQueueSync) _messageQueue.Dequeue();
                        }
                    }
                    if (_clearQueueOnFail)
                    {
                        lock (MessageQueueSync) _messageQueue.Clear();
                    }
                    CreateServerSocket();
                    continue;
                }
                // Everything went well lets dequeue if we didn't do that before
                if (!dequeueOnFail)
                {
                    lock (MessageQueueSync) _messageQueue.Dequeue();
                }
                NotifyMessageSentOut(readonlyMsg, true);
                var data = mqMessage.FrameCount > 1 ? mqMessage[2].ConvertToString() : mqMessage.First.ConvertToString();
                _logger.Trace("We did get a reply {0}...", data);
                if (_messageQueue.Count == 0)
                {
                    _messageSendResetEvent.Reset();
                }
            }
            _messageReplyReceived.OnError(new EndOfStreamException("Message queue is stopping."));
            _logger.Debug("Stopping dequeue loop...");
        }
        public Action<NetMQMessage> Send(NetMQSocket socket, PendingResRequest pendingRequest, Guid requestId)
        {
            var pending = (PendingResRequest<QueuedEventsResponse>) pendingRequest;

            var msg = new NetMQMessage();
            msg.AppendEmptyFrame();
            msg.Append(ResProtocol.ResClient01);
            msg.Append(ResCommands.AcknowledgeQueue);
            msg.Append(requestId.ToByteArray());

            msg.Append(_context);
            msg.Append(_queueId);
            msg.Append(_subscriberId);
            msg.Append(_allocationId.ToNetMqFrame());
            msg.Append(_allocationBatchSize.ToNetMqFrame());
            msg.Append(_allocationTimeoutInMilliseconds.ToNetMqFrame());

            socket.SendMultipartMessage(msg);

            return m =>
            {
                var command = m.Pop().ConvertToString();

                if (command == ResCommands.Error)
                {
                    var errorCode = m.Pop().ConvertToString();
                    var errorDetails = m.Pop().ConvertToString();
                    ErrorResolver.RaiseException(errorCode, errorDetails, pending.SetException);
                    return;
                }

                if (command != ResCommands.QueuedEvents)
                    pending.SetException(new UnsupportedCommandException(command));

                var queueContext = m.Pop().ConvertToString();
                var queueId = m.Pop().ConvertToString();
                var subscriberId = m.Pop().ConvertToString();
                var time = m.PopDateTime();
                var allocationId = m.PopNullableInt64();
                var count = m.PopInt32();

                var events = new EventInStorage[count];

                for (var i = 0; i < count; i++)
                {
                    var id = new Guid(m.Pop().ToByteArray());
                    var streamId = m.Pop().ConvertToString();
                    var context = m.Pop().ConvertToString();
                    var sequence = m.PopInt64();
                    var timestamp = m.PopDateTime();
                    var type = m.PopString();
                    var headers = m.PopStringOrNull();
                    var body = m.PopString();

                    events[i] = new EventInStorage(context, streamId, sequence, type, id, headers, body, timestamp);
                }

                var result = new QueuedEventsResponse(queueContext, queueId, subscriberId, time, allocationId, events);
                pending.SetResult(result);
            };
        }