0

My application should spread some event from a component to some rabbit message publisher.

My component fires the event using ApplicationEventPublisher.publishEvent(e)

On the other side, a message producer should receive the event, process it then publish it to a rabbit queue.

I'm using spring cloud stream and spring cloud function for messaging part:

@Configurationn
MessagingConfig {
@Autowired
StreamBridge sb; 

@EventListener
void handleEvent(Event e){
sb.send("topic", e)
}

Is there to rely on function rather StreamBridge

@Bean
Supplier<Event> messageProducer(){
//Get the event and publish it
}

Or considering ApplicationEventListener as binder

Function<Event, Event> messageProcessor(){
// redirect event to rabbit binder
}

I'm a confused. Thank you for your help.

Katy
  • 1,023
  • 7
  • 19

1 Answers1

0

The @EventListener and StreamBridge combination is an easier way to achieve your task. For a Supplier variant you need some intermediate buffer (Flux?) where you would place your events. And that would be a bit involved with a Flux.create() API: https://projectreactor.io/docs/core/release/reference/#producing.create.

It is possible to use Spring Integration ApplicationEventListeningMessageProducer to catch those events and produce them to the binding's MessageChannel.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118