Search code examples
springspring-kafkaspring-cloud-stream

Spring Cloud Stream - use spring cloud function("Function" specifically) to expose as rest endpoint and publish to a topic


With Spring Cloud Stream - is it possible to use spring cloud function("function" specifically) to expose as rest endpoint and publish to a topic - something like below-

@Bean
  public Function<String,String> postLoginEvent() {
    return valFrmRest -> valFrmRest;
  }

Currently if I try this, the endpoint isn't exposed and I get 404. As a workaround, I used an EmitterProcessor to get input from rest endpoint and separately have a supplier return this processor to publish to a topic. Not sure if what I am asking is technically possible, but it might be a pretty common usecase and it will be nice to have out-of-the-box functionality available. Any thoughts? Thank you in advance for sharing your inputs.


Solution

  • You can have it as a REST endpoint and then use StreamBridge API to publish it programmatically. See the details here.

    Here is a sample using StreamBridge.