使用訊息中介軟體(RabbitMQ)來收集資料
阿新 • • 發佈:2018-12-30
一 新建專案microservice-consumer-movie-ribbon-hystrix-turbine-mq二 為專案新增依賴
三 在配置檔案中新增如下內容,連線RabbitMQ<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-netflix-hystrix-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency>
四 新建專案microservice-hystrix-turbine-mq五 新增依賴server: port: 8010 spring: application: name: microservice-consumer-movie rabbitmq: host: localhost port: 5672 username: guest password: guest eureka: client: serviceUrl: defaultZone:http://localhost:8761/eureka/ instance: prefer-ip-address: true
六 為啟動類添加註解@EnableTurbineStream<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-turbine-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-rabbit</artifactId> </dependency>
package com.itmuch.cloud.study;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream;
@SpringBootApplication
@EnableTurbineStream
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
七 修改配置檔案為server:
port: 8031
spring:
application:
name: microservice-hystrix-turbine
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
eureka:
client:
service-url:
defaultZone:http://localhost:8761/eureka/
instance:
prefer-ip-address: true
八 測試1 啟動eureka2 啟動user3 啟動專案microservice-consumer-movie-ribbon-hystrix-turbine-mq4 啟動專案microservice-hystrix-turbine-mq