springspring-bootspring-integrationspring-integration-amqp

Dependencies for Spring Integration Amqp in Spring Boot


In order to use Spring Integration Amqp in a Spring Boot application, what are the dependencies I need to include?

Spring Boot version is 2.0.5. Current dependencies I have are spring-boot-starter-integration and spring-integration-amqp

Error messages are classes like SimpleMessageListenerContainer and AmqpInboundChannelAdapter are not found on the classpath.

UPDATE: My build.gradle entries --

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
    }
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-integration')
    compile('org.springframework.boot:spring-boot-starter-amqp')
    compile('org.springframework.integration:spring-integration-amqp')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

Solution

  • I had to add the following dependencies to resolve the classes in question (the last in the list did it, using latest spring initalizr, spring-boot 2.0.5)

    dependencies {
        implementation('org.springframework.boot:spring-boot-starter-amqp')
        implementation('org.springframework.boot:spring-boot-starter-integration')
        testImplementation('org.springframework.boot:spring-boot-starter-test')
    
        compile 'org.springframework.integration:spring-integration-amqp'
    }
    

    To be fair, this answer was already given, just not for gradle.

    I am using gradle 4.10.2 on a linux machine, spring-boot initialzr with the options RabbitMQ and Spring-Integration. Here are the changed files:

    build.gradle

    buildscript {
        ext {
            springBootVersion = '2.0.5.RELEASE'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    
    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    
    dependencies {
        implementation('org.springframework.boot:spring-boot-starter-amqp')
        implementation('org.springframework.boot:spring-boot-starter-integration')
        testImplementation('org.springframework.boot:spring-boot-starter-test')
    
        compile 'org.springframework.integration:spring-integration-amqp'
    }
    

    Implementation of Example 12.2.1 Configuring with Java Configuration from the Spring Integration docs:

    package com.example.integrationamqp;
    
    import org.springframework.amqp.rabbit.connection.ConnectionFactory;
    import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.boot.WebApplicationType;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.context.annotation.Bean;
    import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
    import org.springframework.integration.amqp.inbound.AmqpInboundGateway;
    import org.springframework.integration.annotation.ServiceActivator;
    import org.springframework.integration.channel.DirectChannel;
    import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
    import org.springframework.messaging.Message;
    import org.springframework.messaging.MessageChannel;
    import org.springframework.messaging.MessageHandler;
    import org.springframework.messaging.MessagingException;
    
    
    
    @SpringBootApplication
    public class IntegrationAmqpApplication {
    
         public static void main(String[] args) {
            new SpringApplicationBuilder(IntegrationAmqpApplication.class)
                    .web(WebApplicationType.NONE)
                    .run(args);
        }
    
        @Bean
        public MessageChannel amqpInputChannel() {
            return new DirectChannel();
        }
    
        @Bean
        public AmqpInboundChannelAdapter inbound(SimpleMessageListenerContainer listenerContainer,
                                                 @Qualifier("amqpInputChannel") MessageChannel channel) {
            AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);
            adapter.setOutputChannel(channel);
            return adapter;
        }
    
        @Bean
        public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
            SimpleMessageListenerContainer container =
                    new SimpleMessageListenerContainer(connectionFactory);
            container.setQueueNames("foo");
            container.setConcurrentConsumers(2);
            // ...
            return container;
        }
    
        @Bean
        @ServiceActivator(inputChannel = "amqpInputChannel")
        public MessageHandler handler() {
            return new MessageHandler() {
    
                @Override
                public void handleMessage(Message<?> message) throws MessagingException {
                    System.out.println(message.getPayload());
                }
    
            };
        }
    }