private async Task MakePublishRequest <TContent>(
            string pubsubName,
            string topicName,
            TContent content,
            Dictionary <string, string> metadata,
            CancellationToken cancellationToken)
        {
            // Create PublishEventEnvelope
            var envelope = new Autogenerated.PublishEventRequest()
            {
                PubsubName = pubsubName,
                Topic      = topicName,
            };

            if (content != null)
            {
                envelope.Data = TypeConverters.ToJsonByteString(content, this.jsonSerializerOptions);
            }

            if (metadata != null)
            {
                envelope.Metadata.Add(metadata);
            }

            await this.MakeGrpcCallHandleError(
                options => client.PublishEventAsync(envelope, options),
                cancellationToken);
        }
        private async Task MakePublishRequest <TContent>(string topicName, TContent content, CancellationToken cancellationToken)
        {
            // Create PublishEventEnvelope
            var envelope = new Autogenerated.PublishEventRequest()
            {
                Topic = topicName,
            };

            if (content != null)
            {
                envelope.Data = ConvertToByteStringAsync(content, this.jsonSerializerOptions);
            }

            await this.MakeGrpcCallHandleError(
                (options) =>
            {
                return(client.PublishEventAsync(envelope, options));
            },
                cancellationToken);
        }
示例#3
0
        private async Task MakePublishRequest(
            string pubsubName,
            string topicName,
            ByteString content,
            Dictionary <string, string> metadata,
            CancellationToken cancellationToken)
        {
            // Create PublishEventEnvelope
            var envelope = new Autogenerated.PublishEventRequest()
            {
                PubsubName = pubsubName,
                Topic      = topicName,
            };

            if (content != null)
            {
                envelope.Data            = content;
                envelope.DataContentType = Constants.ContentTypeApplicationJson;
            }

            if (metadata != null)
            {
                foreach (var kvp in metadata)
                {
                    envelope.Metadata.Add(kvp.Key, kvp.Value);
                }
            }

            var options = CreateCallOptions(headers: null, cancellationToken);

            try
            {
                await client.PublishEventAsync(envelope, options);
            }
            catch (RpcException ex)
            {
                throw new DaprException("Publish operation failed: the Dapr endpoint indicated a failure. See InnerException for details.", ex);
            }
        }