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)); }
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); }
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())); }