From 9022f777e53e0df8ce3a38aeca1c72489950d0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Tue, 9 Mar 2021 14:38:18 +0800 Subject: [PATCH] feat($Starter): integrate RabbitMQ [skip ci] --- .../application-development-docker.yml | 2 +- .../application-development-local.yml | 2 +- .../main/resources/application-production.yml | 2 +- .../src/main/resources/application-stage.yml | 2 +- .../src/main/resources/application-test.yml | 2 +- .../application-development-docker.yml | 7 ++++- .../application-development-local.yml | 7 ++++- .../main/resources/application-production.yml | 7 ++++- .../src/main/resources/application-stage.yml | 7 ++++- .../src/main/resources/application-test.yml | 7 ++++- .../src/main/resources/application.yml | 2 +- docker/.env | 2 ++ docker/config/redis/redis.conf | 2 +- docker/docker-compose.yml | 4 +-- .../application-development-docker.yml | 7 ++++- .../application-development-local.yml | 7 ++++- .../main/resources/application-production.yml | 7 ++++- .../src/main/resources/application-stage.yml | 7 ++++- .../src/main/resources/application-test.yml | 7 ++++- .../src/main/resources/application.yml | 2 +- .../application-development-docker.yml | 7 ++++- .../application-development-local.yml | 7 ++++- .../main/resources/application-production.yml | 7 ++++- .../src/main/resources/application-stage.yml | 7 ++++- .../src/main/resources/application-test.yml | 7 ++++- muscle-mis/src/main/resources/application.yml | 2 +- .../application-development-docker.yml | 7 ++++- .../application-development-local.yml | 7 ++++- .../main/resources/application-production.yml | 7 ++++- .../src/main/resources/application-stage.yml | 7 ++++- .../src/main/resources/application-test.yml | 7 ++++- .../src/main/resources/application.yml | 2 +- spring-cloud-starter/pom.xml | 9 ++++++ .../MafAutoConfiguration.java | 3 +- .../configuration/RabbitmqConfiguration.java | 29 +++++++++++++++++++ 35 files changed, 174 insertions(+), 33 deletions(-) create mode 100644 spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/RabbitmqConfiguration.java diff --git a/api-gateway/src/main/resources/application-development-docker.yml b/api-gateway/src/main/resources/application-development-docker.yml index ba7b596d..13972c6a 100644 --- a/api-gateway/src/main/resources/application-development-docker.yml +++ b/api-gateway/src/main/resources/application-development-docker.yml @@ -6,4 +6,4 @@ spring: redis: host: maf.redis.development-docker port: 6379 - password: 123456 + password: maf@redis diff --git a/api-gateway/src/main/resources/application-development-local.yml b/api-gateway/src/main/resources/application-development-local.yml index 404e83dc..9d0fa096 100644 --- a/api-gateway/src/main/resources/application-development-local.yml +++ b/api-gateway/src/main/resources/application-development-local.yml @@ -6,4 +6,4 @@ spring: redis: host: localhost port: 6379 - password: 123456 + password: maf@redis diff --git a/api-gateway/src/main/resources/application-production.yml b/api-gateway/src/main/resources/application-production.yml index 20803493..c7a66d0f 100644 --- a/api-gateway/src/main/resources/application-production.yml +++ b/api-gateway/src/main/resources/application-production.yml @@ -6,4 +6,4 @@ spring: redis: host: maf.redis.production port: 6379 - password: 123456 + password: maf@redis diff --git a/api-gateway/src/main/resources/application-stage.yml b/api-gateway/src/main/resources/application-stage.yml index c9fa5331..b549c24e 100644 --- a/api-gateway/src/main/resources/application-stage.yml +++ b/api-gateway/src/main/resources/application-stage.yml @@ -6,4 +6,4 @@ spring: redis: host: maf.redis.stage port: 6379 - password: 123456 + password: maf@redis diff --git a/api-gateway/src/main/resources/application-test.yml b/api-gateway/src/main/resources/application-test.yml index 621f7b6b..12fbf50b 100644 --- a/api-gateway/src/main/resources/application-test.yml +++ b/api-gateway/src/main/resources/application-test.yml @@ -6,4 +6,4 @@ spring: redis: host: maf.redis.test port: 6379 - password: 123456 + password: maf@redis diff --git a/auth-center/src/main/resources/application-development-docker.yml b/auth-center/src/main/resources/application-development-docker.yml index 852228ed..bc09aa48 100644 --- a/auth-center/src/main/resources/application-development-docker.yml +++ b/auth-center/src/main/resources/application-development-docker.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.development-docker port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.development-docker + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/auth-center/src/main/resources/application-development-local.yml b/auth-center/src/main/resources/application-development-local.yml index 31a9e435..3819410a 100644 --- a/auth-center/src/main/resources/application-development-local.yml +++ b/auth-center/src/main/resources/application-development-local.yml @@ -10,7 +10,12 @@ spring: redis: host: localhost port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: localhost + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq logging: # Configure logging level for SFTP/JSCH diff --git a/auth-center/src/main/resources/application-production.yml b/auth-center/src/main/resources/application-production.yml index 652a6be6..6fa7da46 100644 --- a/auth-center/src/main/resources/application-production.yml +++ b/auth-center/src/main/resources/application-production.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.production port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.production + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/auth-center/src/main/resources/application-stage.yml b/auth-center/src/main/resources/application-stage.yml index 08188444..5408ddbc 100644 --- a/auth-center/src/main/resources/application-stage.yml +++ b/auth-center/src/main/resources/application-stage.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.stage port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.stage + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/auth-center/src/main/resources/application-test.yml b/auth-center/src/main/resources/application-test.yml index 8f63dfb4..48ba4f69 100644 --- a/auth-center/src/main/resources/application-test.yml +++ b/auth-center/src/main/resources/application-test.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.test port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.test + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/auth-center/src/main/resources/application.yml b/auth-center/src/main/resources/application.yml index b9874f8f..fe8250b8 100644 --- a/auth-center/src/main/resources/application.yml +++ b/auth-center/src/main/resources/application.yml @@ -82,7 +82,7 @@ spring: url-pattern: /druid/* reset-enable: false login-username: root - login-password: 123456 + login-password: maf_druid_password allow: redis: database: 0 diff --git a/docker/.env b/docker/.env index 4f88dd86..4d3eec6d 100644 --- a/docker/.env +++ b/docker/.env @@ -64,3 +64,5 @@ MAF_MYSQL_USER=maf_mysql_rw MAF_MYSQL_PASSWORD=maf@mysql MAF_ELASTICSEARCH_PASSWORD=maf@elasticsearch MAF_TIMEZONE=Asia/Hong_Kong +MAF_RABBITMQ_USER=maf_rabbitmq_su +MAF_RABBITMQ_PASSWORD=maf@rabbitmq diff --git a/docker/config/redis/redis.conf b/docker/config/redis/redis.conf index f1008519..ba888a00 100644 --- a/docker/config/redis/redis.conf +++ b/docker/config/redis/redis.conf @@ -787,7 +787,7 @@ acllog-max-len 128 # AUTH as usually, or more explicitly with AUTH default # if they follow the new protocol: both will work. # -requirepass 123456 +requirepass maf@redis # Command renaming (DEPRECATED). # diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 542e1e53..882d1e71 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -67,8 +67,8 @@ services: - ./plugin/rabbitmq/rabbitmq_delayed_message_exchange-3.8.9-0199d11c.ez:/plugins/rabbitmq_delayed_message_exchange-3.8.9-0199d11c.ez - ./plugin/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins environment: - RABBITMQ_DEFAULT_USER: rabbitmq_su - RABBITMQ_DEFAULT_PASS: rabbitmq_password + RABBITMQ_DEFAULT_USER: ${MAF_RABBITMQ_USER} + RABBITMQ_DEFAULT_PASS: ${MAF_RABBITMQ_PASSWORD} networks: muscle_and_fitness_network: diff --git a/exercise-mis/src/main/resources/application-development-docker.yml b/exercise-mis/src/main/resources/application-development-docker.yml index 852228ed..bc09aa48 100644 --- a/exercise-mis/src/main/resources/application-development-docker.yml +++ b/exercise-mis/src/main/resources/application-development-docker.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.development-docker port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.development-docker + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/exercise-mis/src/main/resources/application-development-local.yml b/exercise-mis/src/main/resources/application-development-local.yml index 43cc4e7e..0834dedb 100644 --- a/exercise-mis/src/main/resources/application-development-local.yml +++ b/exercise-mis/src/main/resources/application-development-local.yml @@ -10,7 +10,12 @@ spring: redis: host: localhost port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: localhost + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/exercise-mis/src/main/resources/application-production.yml b/exercise-mis/src/main/resources/application-production.yml index 652a6be6..6fa7da46 100644 --- a/exercise-mis/src/main/resources/application-production.yml +++ b/exercise-mis/src/main/resources/application-production.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.production port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.production + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/exercise-mis/src/main/resources/application-stage.yml b/exercise-mis/src/main/resources/application-stage.yml index c5500a94..42461dec 100644 --- a/exercise-mis/src/main/resources/application-stage.yml +++ b/exercise-mis/src/main/resources/application-stage.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.stage port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.stage + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/exercise-mis/src/main/resources/application-test.yml b/exercise-mis/src/main/resources/application-test.yml index f2a6c7f6..63ae100b 100644 --- a/exercise-mis/src/main/resources/application-test.yml +++ b/exercise-mis/src/main/resources/application-test.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.test port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.test + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/exercise-mis/src/main/resources/application.yml b/exercise-mis/src/main/resources/application.yml index 922dff18..f3680791 100644 --- a/exercise-mis/src/main/resources/application.yml +++ b/exercise-mis/src/main/resources/application.yml @@ -84,7 +84,7 @@ spring: url-pattern: /druid/* reset-enable: false login-username: root - login-password: 123456 + login-password: maf_druid_password allow: redis: database: 0 diff --git a/muscle-mis/src/main/resources/application-development-docker.yml b/muscle-mis/src/main/resources/application-development-docker.yml index 852228ed..bc09aa48 100644 --- a/muscle-mis/src/main/resources/application-development-docker.yml +++ b/muscle-mis/src/main/resources/application-development-docker.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.development-docker port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.development-docker + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/muscle-mis/src/main/resources/application-development-local.yml b/muscle-mis/src/main/resources/application-development-local.yml index 05ba88ba..3a582072 100644 --- a/muscle-mis/src/main/resources/application-development-local.yml +++ b/muscle-mis/src/main/resources/application-development-local.yml @@ -10,7 +10,12 @@ spring: redis: host: localhost port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: localhost + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq logging: level: diff --git a/muscle-mis/src/main/resources/application-production.yml b/muscle-mis/src/main/resources/application-production.yml index 652a6be6..6fa7da46 100644 --- a/muscle-mis/src/main/resources/application-production.yml +++ b/muscle-mis/src/main/resources/application-production.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.production port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.production + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/muscle-mis/src/main/resources/application-stage.yml b/muscle-mis/src/main/resources/application-stage.yml index 08188444..5408ddbc 100644 --- a/muscle-mis/src/main/resources/application-stage.yml +++ b/muscle-mis/src/main/resources/application-stage.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.stage port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.stage + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/muscle-mis/src/main/resources/application-test.yml b/muscle-mis/src/main/resources/application-test.yml index 8f63dfb4..48ba4f69 100644 --- a/muscle-mis/src/main/resources/application-test.yml +++ b/muscle-mis/src/main/resources/application-test.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.test port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.test + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq sftp: client: diff --git a/muscle-mis/src/main/resources/application.yml b/muscle-mis/src/main/resources/application.yml index ca19b3d9..6f375a6c 100644 --- a/muscle-mis/src/main/resources/application.yml +++ b/muscle-mis/src/main/resources/application.yml @@ -72,7 +72,7 @@ spring: url-pattern: /druid/* reset-enable: false login-username: root - login-password: 123456 + login-password: maf_druid_password allow: redis: database: 0 diff --git a/spring-boot-admin/src/main/resources/application-development-docker.yml b/spring-boot-admin/src/main/resources/application-development-docker.yml index 1fc3fafb..3211b3b2 100644 --- a/spring-boot-admin/src/main/resources/application-development-docker.yml +++ b/spring-boot-admin/src/main/resources/application-development-docker.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.development-docker port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.development-docker + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq maf: configuration: diff --git a/spring-boot-admin/src/main/resources/application-development-local.yml b/spring-boot-admin/src/main/resources/application-development-local.yml index ac987f06..c313680a 100644 --- a/spring-boot-admin/src/main/resources/application-development-local.yml +++ b/spring-boot-admin/src/main/resources/application-development-local.yml @@ -10,7 +10,12 @@ spring: redis: host: localhost port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: localhost + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq maf: configuration: diff --git a/spring-boot-admin/src/main/resources/application-production.yml b/spring-boot-admin/src/main/resources/application-production.yml index 35a125b1..a82244c0 100644 --- a/spring-boot-admin/src/main/resources/application-production.yml +++ b/spring-boot-admin/src/main/resources/application-production.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.production port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.production + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq maf: configuration: diff --git a/spring-boot-admin/src/main/resources/application-stage.yml b/spring-boot-admin/src/main/resources/application-stage.yml index bd704956..07cc87c7 100644 --- a/spring-boot-admin/src/main/resources/application-stage.yml +++ b/spring-boot-admin/src/main/resources/application-stage.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.stage port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.stage + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq maf: configuration: diff --git a/spring-boot-admin/src/main/resources/application-test.yml b/spring-boot-admin/src/main/resources/application-test.yml index c9250d35..68f67681 100644 --- a/spring-boot-admin/src/main/resources/application-test.yml +++ b/spring-boot-admin/src/main/resources/application-test.yml @@ -10,7 +10,12 @@ spring: redis: host: maf.redis.test port: 6379 - password: 123456 + password: maf@redis + rabbitmq: + host: maf.rabbitmq.test + port: 5672 + username: maf_rabbitmq_su + password: maf@rabbitmq maf: configuration: diff --git a/spring-boot-admin/src/main/resources/application.yml b/spring-boot-admin/src/main/resources/application.yml index e3b30eb2..8c82678c 100644 --- a/spring-boot-admin/src/main/resources/application.yml +++ b/spring-boot-admin/src/main/resources/application.yml @@ -77,7 +77,7 @@ spring: url-pattern: /druid/* reset-enable: false login-username: root - login-password: 123456 + login-password: maf_druid_password allow: redis: database: 0 diff --git a/spring-cloud-starter/pom.xml b/spring-cloud-starter/pom.xml index 1dd617b8..8ebf3b34 100644 --- a/spring-cloud-starter/pom.xml +++ b/spring-cloud-starter/pom.xml @@ -41,6 +41,15 @@ org.springframework.boot spring-boot-starter-data-redis + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.amqp + spring-rabbit-test + test + org.springframework.boot spring-boot-configuration-processor diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/MafAutoConfiguration.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/MafAutoConfiguration.java index b0adaaec..0b365c75 100644 --- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/MafAutoConfiguration.java +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/MafAutoConfiguration.java @@ -55,7 +55,8 @@ SftpConfiguration.class, WebSecurityConfiguration.class, RestTemplateConfiguration.class, - AsyncConfiguration.class + AsyncConfiguration.class, + RabbitmqConfiguration.class }) public class MafAutoConfiguration { @PostConstruct diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/RabbitmqConfiguration.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/RabbitmqConfiguration.java new file mode 100644 index 00000000..add61855 --- /dev/null +++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/configuration/RabbitmqConfiguration.java @@ -0,0 +1,29 @@ +package com.jmsoftware.maf.springcloudstarter.configuration; + +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.springframework.amqp.core.TopicExchange; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Description: RabbitmqConfiguration, change description here. + * + * @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 3/9/2021 11:31 AM + **/ +@Slf4j +@Configuration +public class RabbitmqConfiguration { + public final String topicExchangeName; + + public RabbitmqConfiguration(MafProjectProperty mafProjectProperty) { + topicExchangeName = String.format("%s-topic-exchange", mafProjectProperty.getProjectParentArtifactId()); + } + + @Bean + TopicExchange topicExchange() { + val exchange = new TopicExchange(topicExchangeName); + log.info("Created topic exchange: {}", exchange); + return exchange; + } +}