[英]How to trigger both Azure Function by Service Bus message and output message to Service Bus within single Azure Function
I need to trigger an Azure Function based on Service Bus message that will do some logic and will write back to Service Bus some message that will potentially trigger another Azure function etc.. I need to trigger an Azure Function based on Service Bus message that will do some logic and will write back to Service Bus some message that will potentially trigger another Azure function etc..
I have lack of understanding how to do it properly in standard way.我缺乏理解如何以标准方式正确地做到这一点。
Based on this document Azure Service Bus trigger for Azure Functions we can do first part: trigger azure function by Service Bus message. Based on this document Azure Service Bus trigger for Azure Functions we can do first part: trigger azure function by Service Bus message.
Code:代码:
@FunctionName("sbtopicprocessor")
public void run(
@ServiceBusTopicTrigger(
name = "message",
topicName = "mytopicname",
subscriptionName = "mysubscription",
connection = "ServiceBusConnection"
) String message,
final ExecutionContext context
) {
context.getLogger().info(message);
}
Based on this document Azure Service Bus output binding for Azure Functions we can do second part: trigger output message to Service Bus. Based on this document Azure Service Bus output binding for Azure Functions we can do second part: trigger output message to Service Bus.
Code:代码:
@FunctionName("sbtopicsend")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@ServiceBusTopicOutput(name = "message", topicName = "mytopicname", subscriptionName = "mysubscription", connection = "ServiceBusConnection") OutputBinding<String> message,
final ExecutionContext context) {
String name = request.getBody().orElse("Azure Functions");
message.setValue(name);
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
But I need both input / output functionalities within one function?但是我需要一个 function 中的两个输入/output 功能? Should I call second function from the first one via http which seems for me a little bit awkward or should I use Service bus sdk within fist function.
Should I call second function from the first one via http which seems for me a little bit awkward or should I use Service bus sdk within fist function.
Thanks for any help.谢谢你的帮助。
I don't work with Java but you can combine the Trigger and the Output in one function.我不使用 Java,但您可以将触发器和 Output 组合在一个 function 中。
@FunctionName("sbtopicprocessor")
public void run(
@ServiceBusTopicTrigger(
name = "message",
topicName = "mytopicname",
subscriptionName = "mysubscription",
connection = "ServiceBusConnection"
) String messageRequest,
@ServiceBusTopicOutput(name = "message", topicName = "mytopicname", subscriptionName = "mysubscription", connection = "ServiceBusConnection") OutputBinding<String> message, final ExecutionContext context
) {
message.setValue(messageRequest.name);
}
You can combine any type of Trigger with any type of Output in one function.您可以将任何类型的触发器与任何类型的 Output 组合在一个 function 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.