Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions with CloudEvent and KNative cause events on response #1091

Open
cldfzn opened this issue Nov 7, 2023 · 0 comments
Open

Functions with CloudEvent and KNative cause events on response #1091

cldfzn opened this issue Nov 7, 2023 · 0 comments

Comments

@cldfzn
Copy link

cldfzn commented Nov 7, 2023

I'm trying out spring-cloud-function with a KNative installation. I have simple spring boot application with the following configuration:

@Configuration
class CloudEventConfiguration {
    private val logger = KotlinLogging.logger {}

    @Bean
    fun log(): (Message<String>) -> Unit = { input ->
        logger.error { input }
    }
}
spring:
  cloud:
    function:
      web:
        path: /events
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: spring-trigger
  namespace: knative-eventing
  annotations:
    knative-eventing-injection: enabled
spec:
  broker: rabbitmq-broker
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: spring
      namespace: default
    uri: /events/hire

When I set up a KNative trigger to call /events/log with a cloud event, the response creates a new cloud event to be triggered with an empty payload:

< 202 ACCEPTED Accepted
< webtestclient-request-id: [1]
< ce-id: [12345]
< ce-specversion: [1.0]
< ce-type: [io.spring.event]
< ce-source: [https://spring.io/events]
< uri: [/events/log]

This seems to cause an infinite loop, since it's the same message headers, creating the same message with no payload. I'm not sure if I'm doing something incorrect here or if it's not the intended use case for spring-cloud-function. If I create an endpoint, then the event propagation doesn't occur (since there are no ce headers):

    @Bean
    fun router(): RouterFunction<ServerResponse> = coRouter {
        POST("/events/log") { req ->
            val body = req.awaitBody<String>()
            logger.error { body }
            accepted().buildAndAwait()
        }
    }
@cldfzn cldfzn changed the title Functions with CloudEvent cause knative events on response Functions with CloudEvent and KNative cause events on response Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant