1

I combine both Spring Cloud Function for GCP and Spring Cloud Stream for PubSub in the same project. I have one function which is an entrypoint for GCP CF defined in my properties spring.cloud.function.definition=gcpFunction

I bridge the result of the function with Spring Cloud Stream binding by StreamBridge.

Unexpectedly Spring Cloud Stream also automatically binds the gcpFunction function and creates an unwanted topic in PubSub. I would like to exclude the function from the automatic binding for Spring Cloud Stream. The only workaround I found is to bind Spring Cloud Function explicitly to none existing function e.g. spring.cloud.stream.function.definition=doNotBindFunction

This is not ideal because Spring during startup prints some warnings about a missing function and also looks a bit hacky. Is there any other recommended solution?

I looked at the following topics but seems like they don't really solve many problem Is it possible to disable spring-cloud-stream's functional binding for a specific method? as @SpringBootApplication(exclude = ContextFunctionCatalogAutoConfiguration.class) disables also configuration for my gcpFunction

Marious
  • 143
  • 1
  • 11

1 Answers1

0

Try setting spring.cloud.stream.function.autodetect=false. This will turn off autodiscovery of functional beans (refdoc).

Elena Felder
  • 456
  • 3
  • 8
  • I tried, and it did not work. I think this flag does not help if you have defined `spring.cloud.function.definition` But if I don't define this property Spring would not bind my function to GCP adapter. – Marious Mar 31 '22 at 22:24
  • From my understanding when I have defined `spring.cloud.stream.function.definition` it would activate org.springframework.cloud.stream.function.FunctionConfiguration which takes priority on function discovery. Otherwise it uses somewhere some defaults which take probably whatever is visible in function catalogue via "spring.cloud.function.definition" – Marious Mar 31 '22 at 22:57
  • You can see right here https://github.com/spring-cloud/spring-cloud-stream/blob/b4c6ec8332c73ca62b14bb8ad7b1cbbd0644e411/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/function/FunctionConfiguration.java#L978 The definition is taken from "spring.cloud.function.definition" and autodetect flag would just prevent find anything (I guess `functionCatalog.lookup("")`) in the function catalogue `"spring.cloud.function.definition"` is a default when no `spring.cloud.stream.function.definition` is defined which is not a good default in my case – Marious Mar 31 '22 at 23:10
  • I could possibly register the GCP function on my own programmatically e.g via Bean Definitions and delete spring.cloud.function.definition and set spring.cloud.stream.function.autodetect=false this migth work... – Marious Mar 31 '22 at 23:18
  • Sounds like a good feature request for Spring Cloud Stream. – Elena Felder Apr 01 '22 at 12:50