예제 #1
0
        public async ValueTask <string> PublishAsync(byte[] data, int offset, int count, string topic, IEnumerable <string> tags, MessageTopicPublishOptions options = null, CancellationToken cancellation = default)
        {
            if (data == null || data.Length == 0)
            {
                return(null);
            }

            if (offset < 0 || offset > data.Length - 1)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (count < 1)
            {
                count = data.Length - offset;
            }
            else
            {
                if (offset + count > data.Length)
                {
                    throw new ArgumentOutOfRangeException(nameof(count));
                }
            }

            var response = await _http.PostAsync(MESSAGE_SEND_URL, CreateMessageRequest(data, offset, count, tags), cancellation);

            if (cancellation.IsCancellationRequested)
            {
                return(null);
            }

            var content = await response.Content.ReadAsStreamAsync(cancellation);

            return(MessageUtility.GetMessageResponseId(content));
        }
예제 #2
0
 public ValueTask <string> PublishAsync(ReadOnlyMemory <byte> data, string topic, IEnumerable <string> tags, MessageTopicPublishOptions options = null, CancellationToken cancellation = default)
 {
     return(this.PublishAsync(data.ToArray(), 0, data.Length, topic, tags, options, cancellation));
 }