简体   繁体   English

How to trigger both Azure Function by Service Bus message and output message to Service Bus within single Azure Function

[英]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.

相关问题 azure功能服务总线输出消息属性 - azure function service bus output message properties 具有服务总线触发器的Azure Function中的自动转发消息 - Auto forward message in Azure Function with Service Bus trigger 使用代理消息在门户中测试Azure功能服务总线触发器 - Testing an Azure Function Service Bus Trigger in the Portal with a Brokered Message 如何将消息推送到 azure 服务总线并触发 azure 函数以记录它看到的消息 - how to push a message onto azure service bus and trigger an azure function to log it sees the message Azure功能未将消息发布到服务总线 - Azure Function Not Publishing Message to Service Bus 如何从azure功能向azure服务总线添加消息? - How to add message to azure service bus from azure function? 如何将二进制消息从 Azure 函数发送到 Azure 服务总线 - How to send a binary message from Azure Function to Azure Service Bus 当新消息进入服务总线队列时,Azure 函数(服务总线触发器)不启动 - Azure Function (Service Bus Trigger) Not Getting started when a new message comes into the service bus queue 如何将服务总线消息标记为从 Azure 函数处理? - How mark a Service Bus message as processed from an Azure function? 如何从 Azure Function 更新服务总线消息? - How to renew Service Bus message from Azure Function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM