public static void Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "topic/{topicName}")] HttpRequest req, [DaprPublish(PubSubName = "%PubSubName%", Topic = "{topicName}")] out DaprPubSubEvent pubSubEvent, ILogger log) { string requestBody = new StreamReader(req.Body).ReadToEnd(); pubSubEvent = new DaprPubSubEvent(requestBody); }
public static void Run( [DaprTopicTrigger(Topic = "A")] CloudEvent subEvent, [DaprPublish(Topic = "B")] out object pubEvent, ILogger log) { log.LogInformation("C# function processed a TransferEventBetweenTopics request from the Dapr Runtime."); pubEvent = new DaprPubSubEvent("Transfer from Topic A: " + subEvent.Data); }
public async Task Publish_ReturnValue_Bound() { var input = new DaprPubSubEvent("Hello, world!"); await this.CallFunctionAsync(nameof(Functions.DaprPubSubEventReturnValueBound), "input", input); SavedHttpRequest req = this.GetSinglePublishRequest(); string expectedValue = JsonConvert.SerializeObject(input.Payload); Assert.Equal($"/v1.0/publish/MyBoundPubSub/MyBoundTopic", req.Path); Assert.Equal(expectedValue, req.ContentAsString); }
public async Task Publish_NoTopicSpecified() { // No topic is specified var input = new DaprPubSubEvent("Hello, world!"); FunctionInvocationException error = await Assert.ThrowsAsync <FunctionInvocationException>(() => this.CallFunctionAsync(nameof(Functions.DaprPubSubEventReturnValueAnyTopic), "input", input)); // The exception message should reflect the fact that no topic was specified ArgumentException innerError = Assert.IsType <ArgumentException>(error.GetBaseException()); Assert.Contains("No topic", innerError.Message); // No requests should have been sent Assert.Empty(this.GetDaprRequests()); }
public static DaprPubSubEvent DaprPubSubEventReturnValueBound(DaprPubSubEvent input) => input;
public static DaprPubSubEvent DaprPubSubEventReturnValueAnyTopic(DaprPubSubEvent input) => input;