Exemple #1
0
        public Task <MsgOp> RequestAsync(string subject, ReadOnlyMemory <byte> body, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();

            if (body.Length > _connection.ServerInfo.MaxPayload)
            {
                throw NatsException.ExceededMaxPayload(_connection.ServerInfo.MaxPayload, body.Length);
            }

            return(_connectionInfo.UseInboxRequests
                ? DoRequestUsingInboxAsync(subject, body, cancellationToken)
                : DoRequestAsync(subject, body, cancellationToken));
        }
Exemple #2
0
        public async Task PubAsync(string subject, ReadOnlyMemory <byte> body, string replyTo = null)
        {
            ThrowIfDisposed();

            if (body.Length > _connection.ServerInfo.MaxPayload)
            {
                throw NatsException.ExceededMaxPayload(_connection.ServerInfo.MaxPayload, body.Length);
            }

            await _connection.WithWriteLockAsync(async (writer, arg) =>
            {
                var(subjectIn, bodyIn, replyToIn) = arg;
                await PubCmd.WriteAsync(writer, subjectIn, replyToIn, bodyIn).ConfigureAwait(false);
                if (ShouldAutoFlush)
                {
                    await writer.FlushAsync().ConfigureAwait(false);
                }
            }, Tuple.Create(subject.AsMemory(), body, replyTo.AsMemory())).ConfigureAwait(false);
        }
Exemple #3
0
        public void Pub(string subject, ReadOnlyMemory <byte> body, string replyTo = null)
        {
            ThrowIfDisposed();

            if (body.Length > _connection.ServerInfo.MaxPayload)
            {
                throw NatsException.ExceededMaxPayload(_connection.ServerInfo.MaxPayload, body.Length);
            }

            _connection.WithWriteLock((writer, arg) =>
            {
                var(subjectIn, bodyIn, replyToIn) = arg;

                PubCmd.Write(writer, subjectIn.Span, replyToIn.Span, bodyIn);
                if (ShouldAutoFlush)
                {
                    writer.Flush();
                }
            }, Tuple.Create(subject.AsMemory(), body, replyTo.AsMemory()));
        }