Check out the full series of Questions Management tutorial here.
I showed you about the Turbine Stream with RabbitMQ in this tutorial, to implement it for Questions Management, first, we need to add Hystrix Stream and Stream Rabbit dependency for API and Composite services as follows:
1 2 3 4 5 6 7 8 |
<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> |
Next, we need to declare information about RabbitMQ for these services in their application.properties file:
1 2 3 4 |
spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest |
In the support-turbine-stream project, you need to add annotation @EnableTurbineStream to the SupportTurbineStreamApplication class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package com.huongdanjava.qm.turbinestream; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream; @SpringBootApplication @EnableTurbineStream public class SupportTurbineStreamApplication { public static void main(String[] args) { SpringApplication.run(SupportTurbineStreamApplication.class, args); } } |
and configure the application.properties file as follows:
1 2 3 4 5 6 7 8 9 10 |
spring.application.name=Support Turbine Stream server.port=8580 spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest eureka.client.register-with-eureka=false eureka.client.fetch-registry=false |
The last thing we need to do is, because the latest version of Spring Cloud Netflix does not work with Hystrix Stream and Turbine Stream, we need to downgrade its version to Greenwich.M1 in the pom.xml file of parent project questions-management :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
<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.huongdanjava</groupId> <artifactId>questions-management</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Questions Management System</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.M1</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>core/core-category-service</module> <module>core/core-option-service</module> <module>core/core-question-service</module> <module>composite/composite-question-service</module> <module>composite/composite-option-service</module> <module>api/api-category-service</module> <module>api/api-question-service</module> <module>api/api-option-service</module> <module>support/support-discovery-server</module> <module>support/support-edge-server</module> <module>support/support-monitor-dashboard</module> <module>support/support-turbine-stream</module> </modules> </project> |
That’s it.
Let’s try start MongoDB, RabbitMQ, all services, and support:
Start front-end:
Run Support Hystrix Dashboard and connect to Support Turbine Stream:
Go to the page showing all the questions, then the page displays all categories multiple times, then return to the Hystrix Dashboard screen, you will see the following result:
If I turn off the Core Option Service and then do the above actions again, you will see the following result:
As you can see the display on the Hystrix Dashboard, the call to get all the options are faulty. Based on this report, we will know which service is in need of taking action quickly so that our system will be stable again.