Search code examples
spring-cloud-streamspring-cloud-dataflow

How to mock rabbitmq to test the standalone Spring cloud data flow processor?


I have a SCDF processor using PolledProcessor to poll from the input rabbitmq every second. Is there a way to mock the input rabbitmq so that I can verify the polling behavior?


Solution

  • You don't need to mock RabbitMQ. Use the TestChannelBinder from SpringCloudStream and register a MessageSource<byte[]> to simulate content received from a PollableSource. You need to include the following dependency:

    <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <type>test-jar</type>
            <classifier>test-binder</classifier>
            <scope>test</scope>
    </dependency>
    

    As an example, see https://github.com/spring-cloud/spring-cloud-stream/blob/main/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/PollableConsumerTests.java