To be able to publish events to different topics, we need to declare one MessageChannel per topic in a Java interface and also declare that we want to use it with an EnableBinding annotation. Let's us see how to do this:
We declare our message channels in the MessageSources interface in the ProductCompositeIntegration class and ask Spring to inject an instance of it in the constructor, as follows:
When we want to publish an event on a topic, we use the injected messageSources object. For example, to send a delete event for a product, we can use the outputProducts() method to get a message channel for the product's topic and then use its send() method to publish an event.
To create the message that contains the event, we can use the built-in MessageBuilder class, as follows: