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

@ -9,13 +9,11 @@
debug:当此属性设置为true时将打印出logback内部日志信息实时查看logback运行状态。默认值为false。 -->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 定义日志文件 输入位置 -->
<property name="log_dir" value="logs/ev_cmdb" />
<property name="log_dir" value="logs/ev_cmdb"/>
<!-- 日志最大的历史 30天 -->
<property name="maxHistory" value="30"/>
<!-- ConsoleAppender 控制台输出日志 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 对日志进行格式化 -->
@ -139,13 +137,14 @@
</encoder>
</appender>
<logger name="java.sql.PreparedStatement" value="DEBUG" />
<logger name="java.sql.Connection" value="DEBUG" />
<logger name="java.sql.Statement" value="DEBUG" />
<logger name="com.ibatis" value="DEBUG" />
<logger name="com.ibatis.common.jdbc.SimpleDataSource" value="DEBUG" />
<logger name="java.sql.PreparedStatement" value="DEBUG"/>
<logger name="java.sql.Connection" value="DEBUG"/>
<logger name="java.sql.Statement" value="DEBUG"/>
<logger name="com.ibatis" value="DEBUG"/>
<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="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>
@ -153,12 +152,12 @@
<!-- root级别 DEBUG -->
<root level="DEBUG">
<!-- 控制台输出 -->
<appender-ref ref="STDOUT" />
<appender-ref ref="STDOUT"/>
<!-- 文件输出 -->
<appender-ref ref="ERROR" />
<appender-ref ref="INFO" />
<appender-ref ref="WARN" />
<appender-ref ref="DEBUG" />
<appender-ref ref="TRACE" />
<appender-ref ref="ERROR"/>
<appender-ref ref="INFO"/>
<appender-ref ref="WARN"/>
<appender-ref ref="DEBUG"/>
<appender-ref ref="TRACE"/>
</root>
</configuration>

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