Spring Cloud Stream connection with RabbitMQ

前端 未结 1 665
别那么骄傲
别那么骄傲 2021-01-27 09:39

have a simple Spring-Cloud-Stream project that I try to connect with RabbitMQ, It says its connected but It\'s not working. Did I do something wrong in the code?

相关标签:
1条回答
  • 2021-01-27 10:21

    To setup spring cloud stream with rabbitmq binder implementation you need to configure this in your pom.xml 1.

     <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-stream</artifactId>
     </dependency>
     <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
     </dependency>
     <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-amqp</artifactId>
     </dependency>
    

    then you define this in your application.properties/yaml

    2.

    spring:
        cloud:
            stream:
                bindings:
                    greetingChannel
                        destination: test.greeting
                        group: queue
                rabbit:
                    bindings:
                        greetingChannel:
                            producer:
                                transacted: true //optional
    
    
    1. EnableBinding(HelloBinding.class)
    2. Inject binding and use it
    helloBinding.greeting().send(MessageBuilder
                    .withPayload(...)
                    .build());
    
    1. Setup of rabbitMQ properties
    0 讨论(0)
提交回复
热议问题