在 azure spring boot 函数上使用基于元组的输入输出参数时出现以下错误..
[2021-08-19T10:22:51.771Z] Caused by: java.lang.UnsupportedOperationException: At the moment only Tuple-based function are supporting multiple arguments
[2021-08-19T10:22:51.776Z] at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.parseMultipleValueArguments(SimpleFunctionRegistry.java:879)
[2021-08-19T10:22:51.778Z] at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.convertMultipleOutputArgumentTypeIfNecesary(SimpleFunctionRegistry.java:1180)
[2021-08-19T10:22:51.780Z] at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.convertOutputIfNecessary(SimpleFunctionRegistry.java:1012)
[2021-08-19T10:22:51.781Z] at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:492)
[2021-08-19T10:22:51.784Z] at org.springframework.cloud.function.adapter.azure.FunctionInvoker.handleRequest(FunctionInvoker.java:122)
[2021-08-19T10:22:51.785Z] at com.att.trace.function.HelloHandler.execute(HelloHandler.java:49)
[2021-08-19T10:22:51.786Z] ... 16 more
源代码:
package com.att.trace.function;
import java.util.Optional;
import com.att.trace.function.model.User;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import org.springframework.cloud.function.adapter.azure.FunctionInvoker;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;
import reactor.util.function.Tuples;
public class HelloHandler extends FunctionInvoker<Tuple2<String, Integer>, Tuple3<String, Boolean, Integer>> {
@FunctionName("hello")
public HttpResponseMessage execute(@HttpTrigger(name = "request", methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<User>> request,
ExecutionContext context) {
User user = request.getBody().filter((u -> u.getName() != null))
.orElseGet(() -> new User(request.getQueryParameters().getOrDefault("name", "world")));
context.getLogger().info("Greeting user name: " + user.getName());
Tuple2<String, Integer> base = Tuples.of("one", 1);
Tuple3<String, Boolean, Integer> push_to = handleRequest(base, context);
System.out.println("push_to=" + push_to);
return request.createResponseBuilder(HttpStatus.OK).body("ok")
.header("Content-Type", "application/json").build();
}
}
package com.att.trace.function;
import java.util.function.Function;
import org.springframework.stereotype.Component;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuple3;
import reactor.util.function.Tuples;
@Component
public class Hello implements Function<Tuple2<String, Integer>, Tuple3<String, Boolean, Integer>>{
private static Logger log = LoggerFactory.getLogger(Hello.class);
public Tuple3<String, Boolean, Integer> apply(Tuple2<String, Integer> objects) {
System.out.println("objects.getT1()=" + objects.getT1());
System.out.println("objects.getT2()=" + objects.getT2());
Tuple3<String, Boolean, Integer> output = Tuples.of("one",false,1);
return output;
// return mono.map(user -> new Greeting("Hello, " + user.getName() + "!\n"));
}
}
仅供引用,使用下面的 Spring Boot 启动器。看起来已经在使用最新版本
最佳答案
您可能正在使用 wrong namespace 中的元组
public class HelloHandler extends FunctionInvoker<Tuple2<String, Integer>, Tuple3<String, Boolean, Integer>> {
确保您使用reactor.util.function.Tuple
另一件事对我来说没有意义是 FunctionInvoker<Tuple2<String, Integer>, Tuple3<String, Boolean, Integer>>
在函数调用程序中,您说您期望 Tuple2,但在执行方法中您映射 User
execute(@HttpTrigger(name = "request", methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<User>> request
它们应该匹配
关于java - Azure Spring Boot 功能 - 异常 : UnsupportedOperationException: At the moment only Tuple-based function are supporting multiple arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68846308/