예제 #1
0
        public async Task <MsgOp> RequestAsync(string subject, string body, int?timeoutMs = null)
        {
            ThrowIfDisposed();

            EnsureArg.IsNotNullOrWhiteSpace(subject, nameof(subject));
            EnsureArg.IsNotNullOrWhiteSpace(body, nameof(body));

            return(await DoRequestAsync(subject, NatsEncoder.GetBytes(body), timeoutMs).ConfigureAwait(false));
        }
예제 #2
0
        internal static ReadOnlySpan <byte> Generate(bool verbose, Credentials credentials, string name)
        {
            var opString = GenerateConnectionOpString(
                verbose,
                credentials ?? Credentials.Empty,
                name);

            return(NatsEncoder.GetBytes(opString).Span);
        }
예제 #3
0
        private static void FillPreBody(byte[] buff, string subject, string bodyLenString, string replyTo = null)
        {
            buff[0] = Cmd[0];
            buff[1] = Cmd[1];
            buff[2] = Cmd[2];
            buff[3] = NatsEncoder.SpaceByte;

            var curr = 3;

            curr = NatsEncoder.WriteSingleByteUtf8String(buff, subject, curr);

            if (replyTo != null)
            {
                buff[++curr] = NatsEncoder.SpaceByte;
                curr         = NatsEncoder.WriteSingleByteUtf8String(buff, replyTo, curr);
            }
            buff[++curr] = NatsEncoder.SpaceByte;
            NatsEncoder.WriteSingleByteUtf8String(buff, bodyLenString, curr);
        }
예제 #4
0
        private static void Fill(Span <byte> trg, ReadOnlySpan <char> subscriptionId, ReadOnlySpan <char> maxMessagesString)
        {
            trg[0] = Cmd[0];
            trg[1] = Cmd[1];
            trg[2] = Cmd[2];
            trg[3] = Cmd[3];
            trg[4] = Cmd[4];
            trg[5] = NatsEncoder.SpaceByte;

            var nextSlot = 6;

            nextSlot = NatsEncoder.WriteSingleByteChars(trg, nextSlot, subscriptionId);

            if (!maxMessagesString.IsEmpty)
            {
                trg[nextSlot++] = NatsEncoder.SpaceByte;
                nextSlot        = NatsEncoder.WriteSingleByteChars(trg, nextSlot, maxMessagesString);
            }

            NatsEncoder.WriteCrlf(trg, nextSlot);
        }
예제 #5
0
        private static void Fill(Span <byte> trg, ReadOnlySpan <char> subject, ReadOnlySpan <char> subscriptionId, ReadOnlySpan <char> queueGroup)
        {
            trg[0] = Cmd[0];
            trg[1] = Cmd[1];
            trg[2] = Cmd[2];
            trg[3] = NatsEncoder.SpaceByte;

            var nextSlot = 4;

            nextSlot        = NatsEncoder.WriteSingleByteChars(trg, nextSlot, subject);
            trg[nextSlot++] = NatsEncoder.SpaceByte;

            if (!queueGroup.IsEmpty)
            {
                nextSlot        = NatsEncoder.WriteSingleByteChars(trg, nextSlot, queueGroup);
                trg[nextSlot++] = NatsEncoder.SpaceByte;
            }

            nextSlot = NatsEncoder.WriteSingleByteChars(trg, nextSlot, subscriptionId);
            NatsEncoder.WriteCrlf(trg, nextSlot);
        }
예제 #6
0
        private static void FillPreBody(Span <byte> trg, ReadOnlySpan <char> subject, ReadOnlySpan <char> replyTo, ReadOnlySpan <char> bodySize)
        {
            trg[0] = Cmd[0];
            trg[1] = Cmd[1];
            trg[2] = Cmd[2];
            trg[3] = NatsEncoder.SpaceByte;

            var nextSlot = 4;

            nextSlot        = NatsEncoder.WriteSingleByteChars(trg, nextSlot, subject);
            trg[nextSlot++] = NatsEncoder.SpaceByte;

            if (!replyTo.IsEmpty)
            {
                nextSlot        = NatsEncoder.WriteSingleByteChars(trg, nextSlot, replyTo);
                trg[nextSlot++] = NatsEncoder.SpaceByte;
            }

            nextSlot = NatsEncoder.WriteSingleByteChars(trg, nextSlot, bodySize);

            NatsEncoder.WriteCrlf(trg, nextSlot);
        }
예제 #7
0
 public Task <MsgOp> RequestAsync(string subject, string body, CancellationToken cancellationToken = default)
 => RequestAsync(subject, NatsEncoder.GetBytes(body), cancellationToken);
예제 #8
0
 public Task PubAsync(string subject, string body, string replyTo = null)
 => PubAsync(subject, NatsEncoder.GetBytes(body), replyTo);
예제 #9
0
 public void Pub(string subject, string body, string replyTo = null)
 => Pub(subject, NatsEncoder.GetBytes(body), replyTo);
예제 #10
0
 internal static byte[] Generate(string subject, string body, string replyTo = null)
 => Generate(subject, NatsEncoder.GetBytes(body), replyTo);
예제 #11
0
 public string GetPayloadAsString()
 => NatsEncoder.GetString(Payload.Span);
예제 #12
0
 public string GetPayloadAsString()
 {
     return(NatsEncoder.GetString(Payload));
 }