Ejemplo n.º 1
0
        public void Send(SseEvent @event)
        {
            var buffer            = BasicConsumerByteBuffer.Allocate(1, _maxMessageSize);
            var entity            = @event.Sendable();
            var withContentLength = Headers.Copy().And(ResponseHeader.WithContentLength(entity));
            var response          = Response.Of(Response.ResponseStatus.Ok, withContentLength, entity);

            _context.RespondWith(response.Into(buffer));
        }
Ejemplo n.º 2
0
            public override ICompletes <T> With <T>(T response)
            {
                var filtered          = _serverActor._filters.Process((Response)(object)response !);
                var buffer            = BufferFor(filtered);
                var completedResponse = filtered.Include(_correlationId !);

                _requestResponseContext.RespondWith(completedResponse.Into(buffer));
                return((ICompletes <T>) this);
            }
        public void Consume <T>(RequestResponseContext <T> context, ReadOnlySequence <byte> buffer)
        {
            var requestPart = buffer.ToArray().BytesToText(0, (int)buffer.Length);

            _requestBuilder.Append(_remaining).Append(requestPart);
            _remaining = string.Empty;
            if (_requestBuilder.Length >= CurrentExpectedRequestLength)
            {
                // assume currentExpectedRequestLength is length of all
                // requests when multiple are received at one time
                var combinedRequests = _requestBuilder.ToString();
                var combinedLength   = combinedRequests.Length;
                _requestBuilder.Clear(); // reuse

                var startIndex   = 0;
                var currentIndex = 0;
                var last         = false;
                while (!last)
                {
                    if (startIndex > combinedRequests.Length)
                    {
                        _remaining = combinedRequests.Substring(currentIndex);
                        return;
                    }

                    var request = combinedRequests.Substring(startIndex, CurrentExpectedRequestLength);
                    currentIndex += CurrentExpectedRequestLength;
                    startIndex    = startIndex + CurrentExpectedRequestLength;

                    Requests.Add(request);

                    var responseBuffer = new BasicConsumerByteBuffer(1, CurrentExpectedRequestLength);
                    context.RespondWith(responseBuffer.Clear().Put(Converters.TextToBytes(request)).Flip()); // echo back

                    last = currentIndex == combinedLength;

                    UntilConsume.WriteUsing("serverConsume", 1);
                }
            }
        }
Ejemplo n.º 4
0
        private void Send(string entity)
        {
            var buffer = BasicConsumerByteBuffer.Allocate(1, _maxMessageSize);

            _context?.RespondWith(buffer.Put(Encoding.UTF8.GetBytes(entity)).Flip());
        }