From f9154544b8b56fcbd5246d578adb1c692ecbdedf Mon Sep 17 00:00:00 2001 From: "wangiegie@gmail.com" Date: Fri, 17 Nov 2017 09:36:04 +0800 Subject: [PATCH] =?UTF-8?q?ing:=20=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pig-admin-service/pom.xml | 5 ++++ .../admin/listener/LogReceiveListener.java | 19 ++++++++++++ .../src/main/resources/logback.xml | 29 +++++++++---------- .../pig/common/constant/CommonConstant.java | 4 +++ .../pig/gateway/config/RabbitConfig.java | 19 ++++++++++++ .../service/impl/LogSendServiceImpl.java | 8 +++-- 6 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 pig-admin-service/src/main/java/com/github/pig/admin/listener/LogReceiveListener.java create mode 100644 pig-gateway/src/main/java/com/github/pig/gateway/config/RabbitConfig.java diff --git a/pig-admin-service/pom.xml b/pig-admin-service/pom.xml index 066df74f..ff62d482 100644 --- a/pig-admin-service/pom.xml +++ b/pig-admin-service/pom.xml @@ -46,6 +46,11 @@ 2.0 + + + org.springframework.boot + spring-boot-starter-amqp + diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/listener/LogReceiveListener.java b/pig-admin-service/src/main/java/com/github/pig/admin/listener/LogReceiveListener.java new file mode 100644 index 00000000..74816217 --- /dev/null +++ b/pig-admin-service/src/main/java/com/github/pig/admin/listener/LogReceiveListener.java @@ -0,0 +1,19 @@ +package com.github.pig.admin.listener; + +import com.github.pig.common.constant.CommonConstant; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2017/11/17 + */ +@Component +@RabbitListener(queues = CommonConstant.LOG_QUEUE) +public class LogReceiveListener { + @RabbitHandler + public void receive(String text) { + System.out.println("------------------------->" + text); + } +} diff --git a/pig-admin-service/src/main/resources/logback.xml b/pig-admin-service/src/main/resources/logback.xml index f217d014..a63bba5d 100644 --- a/pig-admin-service/src/main/resources/logback.xml +++ b/pig-admin-service/src/main/resources/logback.xml @@ -9,13 +9,11 @@ debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --> - + - - @@ -139,13 +137,14 @@ - - - - - + + + + + - + + @@ -153,12 +152,12 @@ - + - - - - - + + + + + \ No newline at end of file diff --git a/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java b/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java index d24c5bae..2524adbb 100644 --- a/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java +++ b/pig-common/src/main/java/com/github/pig/common/constant/CommonConstant.java @@ -37,4 +37,8 @@ public interface CommonConstant { * 按钮 */ String BUTTON = "1"; + /** + * log rabbit队列名称 + */ + String LOG_QUEUE = "log"; } diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/config/RabbitConfig.java b/pig-gateway/src/main/java/com/github/pig/gateway/config/RabbitConfig.java new file mode 100644 index 00000000..d9dd914f --- /dev/null +++ b/pig-gateway/src/main/java/com/github/pig/gateway/config/RabbitConfig.java @@ -0,0 +1,19 @@ +package com.github.pig.gateway.config; + +import com.github.pig.common.constant.CommonConstant; +import org.springframework.amqp.core.Queue; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author lengleng + * @date 2017/11/16 + * rabbit初始化配置 + */ +@Configuration +public class RabbitConfig { + @Bean + public Queue helloQueue() { + return new Queue(CommonConstant.LOG_QUEUE); + } +} diff --git a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/LogSendServiceImpl.java b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/LogSendServiceImpl.java index c8899ce2..82cb6381 100644 --- a/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/LogSendServiceImpl.java +++ b/pig-gateway/src/main/java/com/github/pig/gateway/service/impl/LogSendServiceImpl.java @@ -1,10 +1,14 @@ package com.github.pig.gateway.service.impl; +import com.github.pig.common.constant.CommonConstant; import com.github.pig.gateway.service.LogSendService; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.HashMap; +import java.util.Map; + /** * @author lengleng * @date 2017/11/16 @@ -13,10 +17,10 @@ import org.springframework.stereotype.Component; @Component public class LogSendServiceImpl implements LogSendService { @Autowired - private AmqpTemplate amqpTemplate; + private AmqpTemplate rabbitTemplate; @Override public void send() { - this.amqpTemplate.convertAndSend("log", "hello"); + rabbitTemplate.convertAndSend(CommonConstant.LOG_QUEUE, "你好"); } }