1

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')
}
user1575148
  • 561
  • 6
  • 28

2 Answers2

1

Add this dependency:

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>

And are you sure you have this one?:

<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
vanillaSugar
  • 523
  • 1
  • 5
  • 14
1

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());
            }

        };
    }
}
chriopp
  • 947
  • 7
  • 12
  • With these dependencies, the compiler is able to find `SimpleMessageListenerContainer` but not `AmqpInboundChannelAdapter` Does the code in Section 12.2.1 of Spring Integration documentation run for you...? [link](https://docs.spring.io/spring-integration/reference/html/amqp.html#amqp-inbound-channel-adapter) – user1575148 Oct 03 '18 at 11:45
  • Yes, compiles and runs smoothly up to a point where it tries to create a connection, which is tried repeatedly. Even deleted all gradle artifacts and rebuilt the application. Using gradle 4.10.2 on a linux system. Spring-boot from initializr with options `RabbitMQ` and `Spring Integration`. – chriopp Oct 03 '18 at 13:02
  • This is a problem with Eclipse. Afer pasting the code from Section 12.2.1, I had resolved the imports in Eclipse using Ctrl-Shift-o. This time, I removed the imports and copied what you had given above. Eclipse still shows error about `AmqpInboundChannelAdapter`, but from the command line `.\gradlew bootRun` runs merrily. – user1575148 Oct 06 '18 at 07:03