Beispiel #1
0
        /// <inheritdoc/>
        public override async Task InvokeBindingAsync <TRequest>(
            string bindingName,
            string operation,
            TRequest data,
            IReadOnlyDictionary <string, string> metadata = default,
            CancellationToken cancellationToken           = default)
        {
            ArgumentVerifier.ThrowIfNullOrEmpty(bindingName, nameof(bindingName));
            ArgumentVerifier.ThrowIfNullOrEmpty(operation, nameof(operation));

            var bytes = TypeConverters.ToJsonByteString <TRequest>(data, this.jsonSerializerOptions);

            _ = await MakeInvokeBindingRequestAsync(bindingName, operation, bytes, metadata, cancellationToken);
        }
        /// <inheritdoc/>
        public override Task PublishEventAsync <TData>(
            string pubsubName,
            string topicName,
            TData data,
            CancellationToken cancellationToken = default)
        {
            ArgumentVerifier.ThrowIfNullOrEmpty(pubsubName, nameof(pubsubName));
            ArgumentVerifier.ThrowIfNullOrEmpty(topicName, nameof(topicName));
            ArgumentVerifier.ThrowIfNull(data, nameof(data));

            var content = TypeConverters.ToJsonByteString(data, this.JsonSerializerOptions);

            return(MakePublishRequest(pubsubName, topicName, content, null, cancellationToken));
        }
Beispiel #3
0
        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 = TypeConverters.ToJsonByteString(content, this.jsonSerializerOptions);
            }

            await this.MakeGrpcCallHandleError(
                options => client.PublishEventAsync(envelope, options),
                cancellationToken);
        }
Beispiel #4
0
        /// <inheritdoc/>
        public override async Task <TResponse> InvokeBindingAsync <TRequest, TResponse>(
            string bindingName,
            string operation,
            TRequest data,
            IReadOnlyDictionary <string, string> metadata = default,
            CancellationToken cancellationToken           = default)
        {
            ArgumentVerifier.ThrowIfNullOrEmpty(bindingName, nameof(bindingName));
            ArgumentVerifier.ThrowIfNullOrEmpty(operation, nameof(operation));

            var bytes    = TypeConverters.ToJsonByteString <TRequest>(data, this.jsonSerializerOptions);
            var response = await MakeInvokeBindingRequestAsync(bindingName, operation, bytes, metadata, cancellationToken);

            try
            {
                return(TypeConverters.FromJsonByteString <TResponse>(response.Data, this.JsonSerializerOptions));
            }
            catch (JsonException ex)
            {
                throw new DaprException("Binding operation failed: the response payload could not be deserialized. See InnerException for details.", ex);
            }
        }