I am trying to make a GCP Cloud function trigger by pubsub message using Spring Cloud framework. I have started with the example provided by Spring team which is quite simple.
But when I execute the command
`curl 127.0.1:8080 -H "Content-Type: application/json" -d '{"data":"aGVsbG8="}'`
I get
`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)`
Also, when I try to to get message from PUBSUB emulator with push subscription, I get
`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.
I have try to set code page chcp 65001
to change windows cmd.exe to UTF-8 but without any sucess.
By the way, the pubsub emulator is working fine when I read message using google backgroudn function like
` @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);
}
`
What do I need to change to make the emulator working with Spring cloud ?
I have many messages to implements and test publish/subcription on local with emulator, I would like to avoid to use POSTMAN and base64 manual conversion for integration testing.
Currently Spring-cloud-function is not working on local with Google PubSub emulator.
Issue has been raised here