0

I have implemented a Spring Cloud Function as shown below:

public class CloudFunc implements Function<MyDTO, MyDTO> {

  @Override
  public MyDTO apply(MyDTO input) {
     input.setValue("3");
     return input;
  }
}

I added below properties in application properties:

spring:
  cloud:
    function:
      definition: cloudFunc
    stream:
      kafka:
        binder:
          brokers: localhost:9092
      bindings:
        cloudFunc-out-0:
          destination: produce-topic
        cloudFunc-in-0:
          destination: consume-topic
          group: sample-group

Since I added stream bindings, if any message is added to "consume-topic", then cloudFunc is triggered with that message and output will be sent to product-topic. If I make Rest call to /cloudFunc, that will return the output to the caller of Rest endpoint. How can I bind it in such a way that, the cloud function is triggered via Rest call and output is sent to Kafka output topic with no code changes and only changes in application properties? Is that possible?

TIA

1 Answers1

0

Use a Consumer<MyDTO> instead of a function and use the StreamBridge to send the output.

See https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_sending_arbitrary_data_to_an_output_e_g_foreign_event_driven_sources

Gary Russell
  • 166,535
  • 14
  • 146
  • 179