Я попытался развернуть Spring Cloud Function
с несколькими функциями в AWS Lambda.
Для доступа по HTTP я создал HTTP API Gateway (not a REST API)
. Я хотел использовать маршрутизацию функций, как описано здесь: https://cloud.spring.io/spring-cloud-static/spring-cloud-function/3.0.1.RELEASE/reference/html/spring-cloud-function.html#_function_routing.
При следующей конфигурации RoutingFunction
должен деактивировать вызов правильной функции на основе function HTTP-Header
:
spring.cloud.function.routing-expression=headers.function
Класс Lambda Handler:
org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler
, а имя настроенной функции (FUNCTION_NAME
): functionRouter
.
Когда я отправляю При запросе к API-шлюзу FunctionRouter получает объект FluxJust вместо объекта Message, потому что RequestHandler кажется издателем. Поэтому я получаю следующее исключение:
EL1008E: Property or field 'headers' cannot be found on object of type
'reactor.core.publisher.FluxJust' - maybe not public or not valid?:
org.springframework.expression.spel.SpelEvaluationException
org.springframework.expression.spel.SpelEvaluationException:
EL1008E: Property or field 'headers' cannot be found on object of type
'reactor.core.publisher.FluxJust' - maybe not public or not valid?
Мой текущий обходной путь - перехватить запрос до его делегирования в RoutingFunction
и попытаться восстановить полезную нагрузку из HashMap
с помощью следующего кода:
@Autowired
RoutingFunction f;
@Bean
public Function<Message<LinkedHashMap>,?> router() {
return value -> {
String json = new JSONObject(value.getPayload()).toString();
Message<?> m = MessageBuilder.createMessage(json, value.getHeaders());
Object result = f.apply(m);
return result;
};
}
Есть ли способ использования шлюза HTTP API в сочетании с Function Routing
в AWS
?