I try to build Java based Azure Function to be triggered by HTTP and sending data to Topic of Service Bus. This is based on sample code. HTTP Trigger works fine(Hello name is returned), but I don't get any data sent to Service Bus. And I do not get error message. I have tested with C# based Function that that "queueconstring" in local.settings.json is correct.
/* 20.3.2020 HTTP Trigger and Topic output binding*/
package com.function;
import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
/**
* Azure Functions with HTTP Trigger.
*/
public class HttpTriggerSBOutputJava {
/**
* This function listens at endpoint "/api/HttpTriggerSBOutputJava". Two ways to invoke it using
"curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTriggerSBOutputJava
* 2. curl {your host}/api/HttpTriggerSBOutputJava?name=HTTP%20Query
*/
@FunctionName("HttpTriggerSBOutputJava")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
@ServiceBusTopicOutput(name = "message", topicName = "ContactInformationChanged", subscriptionName = "Playground", connection = "queueconstring") 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();
}
}