更改消费模块的ymlcloud2022 org.gcl.learn 1.0-SNAPSHOT 4.0.0 cloud-stream-rabbitmq-consumer8802org.springframework.cloud spring-cloud-starter-stream-rabbitorg.springframework.cloud spring-cloud-starter-netflix-eureka-serverorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-actuatororg.springframework.boot spring-boot-devtoolsruntime true org.projectlombok lomboktrue org.springframework.boot spring-boot-starter-testtest junit junittest
server: port: 8802 spring: application: name: cloud-stream-rabbitmq-consumer rabbitmq: host: xxx.xx.xx.xx port: 5672 username: guest password: guest cloud: stream: binders: defaultRabbit: type: rabbit bindings: input: destination: studyExchange content-type: application/json binder: defaultRabbit eureka: client: service-url: defaultZone: http://127.0.0.1:7001/eureka register-with-eureka: true fetch-registry: true更改消费模块的主启动类
package com.gcl.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @EnableEurekaClient @SpringBootApplication public class StreamRabbitMQMain8802 { public static void main(String[] args) { SpringApplication.run( StreamRabbitMQMain8802.class , args ); } }更改消费模块的业务类
package com.gcl.springcloud.service; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; import org.springframework.cloud.stream.messaging.Sink; import org.springframework.messaging.Message; import org.springframework.stereotype.Component; @Component @EnableBinding(Sink.class) public class StreamRabbitMQService { @Value("${server.port}") private String serverPort; @StreamListener(Sink.INPUT) public void input(Message运行message){ System.out.println("***************接收到的消息:" + message.getPayload() + " server.port : " + serverPort ); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)