ing: 新增消息中心

This commit is contained in:
wangiegie@gmail.com 2017-11-17 09:36:04 +08:00
parent a8cb5074be
commit f9154544b8
6 changed files with 67 additions and 17 deletions

View File

@ -46,6 +46,11 @@
<version>2.0</version>
</dependency>
<!--mybatis-plus end -->
<!--rabbitMQ-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>

View File

@ -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);
}
}

View File

@ -14,8 +14,6 @@
<property name="maxHistory" value="30"/>
<!-- ConsoleAppender 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 对日志进行格式化 -->
@ -146,6 +144,7 @@
<logger name="com.ibatis.common.jdbc.SimpleDataSource" value="DEBUG"/>
<logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG"/>
<logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG"/>
<logger name="org.springframework.amqp.rabbit" level="INFO"/>
<logger name="com.github.pig.admin" level="DEBUG" additivity="true">
<appender-ref ref="STDOUT"/>
</logger>

View File

@ -37,4 +37,8 @@ public interface CommonConstant {
* 按钮
*/
String BUTTON = "1";
/**
* log rabbit队列名称
*/
String LOG_QUEUE = "log";
}

View File

@ -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);
}
}

View File

@ -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, "你好");
}
}