[英]Error when use google pubsub emulator and Spring function.adapter.gcp.GcfJarLauncher
我正在尝试使用 Spring Cloud 框架通过 pubsub 消息触发 GCP Cloud function。 我从Spring 团队提供的示例开始,该示例非常简单。
但是当我执行命令时
`curl 127.0.1:8080 -H "Content-Type: application/json" -d '{"data":"aGVsbG8="}'`
我明白了
`AVERTISSEMENT: Failed to execute org.springframework.cloud.function.adapter.gcp.GcfJarLauncher
java.lang.ClassCastException: org.eclipse.jetty.server.Request$1 incompatible with com.example.PubSubMessage
at com.example.BackgroundFunctionMain$$Lambda$349/0x0000000015b164b8.accept(Unknown Source)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeConsumer(SimpleFunctionRegistry.java:969)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:698)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:544)
at org.springframework.cloud.function.adapter.gcp.FunctionInvoker.service(FunctionInvoker.java:98)`
此外,当我尝试通过推送订阅从PUBSUB 模拟器获取消息时,我得到
`AVERTISSEMENT: Failed to execute org.springframework.cloud.function.adapter.gcp.GcfJarLauncher
java.lang.NullPointerException: Cannot invoke "java.lang.String.getBytes(java.nio.charset.Charset)" because "src" is null
at java.base/java.util.Base64$Decoder.decode(Base64.java:589)
at com.example.BackgroundFunctionMain.lambda$pubSubFunction$0(BackgroundFunctionMain.java:27)
at com.example.BackgroundFunctionMain$$Lambda$349/0x0000000072a4b6a8.accept(Unknown Source)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeConsumer(SimpleFunctionRegistry.java:969)`
But, I when I post data from POSTMAN or from git bash windows with curl command it's working fine.
我尝试将代码页chcp 65001
更改为 windows cmd.exe 到 UTF-8 但没有任何成功。
顺便说一句,当我使用谷歌背景 function 阅读消息时,pubsub 模拟器工作正常
` @Override
public void accept(PubSubMessage pubSubMessage, Context context) {
log.info("Received message with id " + context.eventId());
String message = null;
if (pubSubMessage != null && pubSubMessage.getData() != null) {
message =
new String(
Base64.getDecoder().decode(pubSubMessage.getData().getBytes(StandardCharsets.UTF_8)),
StandardCharsets.UTF_8);
}
`
我需要进行哪些更改才能使模拟器与 Spring 云一起使用?
我有很多消息要使用模拟器在本地实现和测试发布/订阅,我想避免使用 POSTMAN 和 base64 手动转换进行集成测试。
目前 Spring-cloud-function 不能在本地使用 Google PubSub 模拟器。
问题已在此处提出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.