4

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

Yeheshuah
  • 1,216
  • 1
  • 13
  • 28
macmagic
  • 41
  • 1
  • 3

1 Answers1

4

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

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I get an issue where the StreamBridge bean is not found in the context, what do you think could be the problem? – Dame Lyngdoh Feb 06 '23 at 20:46
  • Don't ask new questions in comments on old answers; most likely a mis-configured application; ask a new question showing your code and configuration. – Gary Russell Feb 06 '23 at 20:52