I have a rabbitmq exchange [test-exchange] which is a direct exchange that is binded to queue [test-queue] using routing key [test-routing-key].
I am trying to publish messages to this exchange using spring cloud stream but messages are not reaching the queue
My dependency in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
Spring cloud used is Edgware.RELEASE
My source file code is
public interface DemoSource {
@Output("demoChannel")
MessageChannel userChannel();
}
My application file code is
@SpringBootApplication
@EnableBinding(DemoSource.class)
public class PublisherApplication implements CommandLineRunner{
@Autowired
DemoSource demoSource;
public static void main(String[] args) {
SpringApplication sp = new SpringApplication(PublisherApplication.class);
sp.run(args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Sending message...");
User user = new User();
user.setUserId("testId");
user.setUserName("testName");
demoSource.userChannel().send(MessageBuilder.withPayload(user).build());
}
}
My application.properties file is
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.cloud.stream.bindings.demoChannel.destination=test-exchange
spring.cloud.stream.bindings.demoChannel.group=test-routing-key
spring.cloud.stream.bindings.demoChannel.producer.bindingRoutingKey=test-routing-key
spring.cloud.stream.bindings.demoChannel.producer.routing-key-expression= 'test-routing-key'
spring.cloud.stream.rabbit.bindings.demoChannel.producer.exchange-type=direct
spring.cloud.stream.rabbit.bindings.demoChannel.producer.declare-exchange=false
spring.cloud.stream.default.contentType=application/json