How to use Spring Integration to receive message in service layer?

I would like to ask questions about spring Integration with MQTT After reading the documents on the official website

I successfully received the message from the MQTT broker, like this:

public class MqttJavaApplication {

public static void main(String[] args) {
    new SpringApplicationBuilder(MqttJavaApplication.class)

public MessageChannel mqttInputChannel() {
    return new DirectChannel();

public MessageProducer inbound() {
    MqttPahoMessageDrivenChannelAdapter adapter =
            new MqttPahoMessageDrivenChannelAdapter("tcp://localhost:1883", "testClient",
                                             "topic1", "topic2");
    adapter.setConverter(new DefaultPahoMessageConverter());
    return adapter;

@ServiceActivator(inputChannel = "mqttInputChannel")
public MessageHandler handler() {
    return new MessageHandler() {

        public void handleMessage(Message<?> message) throws MessagingException {



But this is a config file. I don't think it is a good idea to handle Message in the config file, but I have found many other MessageHandlers, such as MqttPahoMessageHandler, but I don’t know how to use it. I want to be able to process these messages in the Service layer.