2
votes

I know how to define a producer using the imperative programming approach but I cannot find how to define a producer using the functional programming approach.

I read the Spring Cloud Stream Binder documentation about this, but only found how to define consumer, or consumer & producer (for example, get information from the topic, transform the data and send to another topic).

So, I don't know if it's ok to continue use annotations like @Input, @Ouptut to define a single processor or not, I'm very confused at this point because the library indicates these annotations are deprecated, but I cannot find the example or documentation to define a simple producer to send information to a specific topic.

Thanks!

The documentation link: https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/3.0.10.RELEASE/reference/html/spring-cloud-stream-binder-kafka.html#_kafka_streams_binder

1

1 Answers

3
votes

You can define a Supplier<?> @Bean which will be polled on an interval to generate output (like the @InboundChannelAdapter for @Output channels.

https://docs.spring.io/spring-cloud-stream/docs/3.1.0/reference/html/spring-cloud-stream.html#spring_cloud_function

Or, you can use a StreamBridge to send arbitrary messages to an output destination.

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