Using spring cloud stream with RabbitMQ version. I want to achieve consumer auto-scaling as explained here. with the below configuration, I have 2 concurrent consumers. But SimpleMessageListenerContainer couldn't add consumers dynamically. I had checked SMLC instance is initialized with both concurrency and max-concurrency properties. Is there anything, I am missing to get dynamic scaling?
Note: I had published 200 messages in input1 exchange in rabbitmq.
pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>consumerex</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>graphql</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml file:
spring:
cloud:
stream:
bindings:
input1:
destination: input1
binder: local_rabbit
group: logMessageConsumers
consumer:
concurrency: 2
input2:
destination: input2
binder: local_rabbit
group: logMessageConsumers
binders:
local_rabbit:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /
rabbit:
bindings:
input1:
consumer:
maxConcurrency: 10
server:
port: 0
management:
health:
binders:
enabled: true
App.java file:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
@SpringBootApplication
@EnableBinding(MyProcessor.class)
public class App
{
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@StreamListener("input1")
public void enrichLogMessage(String log) {
//code to keep current consumer busy. So auto scalling can happen.
long time = System.currentTimeMillis() + 120000;
while(time> System.currentTimeMillis()) {
}
System.out.println(Thread.currentThread().getName() + " input1 " + log);
}
@StreamListener("input2")
public void input2(String log) {
System.out.println(Thread.currentThread().getName() + " input2 " + log);
}
}
MyProcessor.java file:
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.messaging.SubscribableChannel;
public interface MyProcessor {
@Input("input1")
SubscribableChannel input1();
@Input("input2")
SubscribableChannel input2();
}