新增activieMQ模块

master
星期八 5 years ago
parent 4fdda6d204
commit 285e58bfcf
  1. 28
      src/main/java/com/lq/code/dto/QueueDto.java
  2. 5
      src/main/java/com/lq/code/util/BeanUtil.java
  3. 16
      src/main/java/com/lq/jms/service/ProductService.java
  4. 25
      src/main/java/com/lq/jms/service/impl/ProductServiceImpl.java
  5. 3
      src/main/resources/spring-import.xml
  6. 46
      src/main/resources/spring/spring-activitMq.xml
  7. 18
      src/test/java/com/lq/SysPermissionServiceTest.java
  8. 25
      src/test/java/com/lq/code/dto/QueueDtoTest.java

@ -2,6 +2,7 @@ package com.lq.code.dto;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Author: qi
@ -10,13 +11,20 @@ import java.util.List;
*/
public class QueueDto<T> {
/**
* 队列内部数组
*/
private List<T> list;
private int index;
/**
* 队列索引 
*/
private AtomicInteger index = new AtomicInteger(0);
public QueueDto() {
this.list = new ArrayList<>();
}
public QueueDto(int size) {
@ -25,14 +33,15 @@ public class QueueDto<T> {
public void add(T t){
list.add(t);
index ++;
index.getAndIncrement();
}
public synchronized T pop(){
public T pop(){
T t = null;
if (hasNext()) {
index--;
t = list.get(index);
index.getAndAdd(-1);
t = list.get(index.get());
}
return t;
}
@ -41,9 +50,10 @@ public class QueueDto<T> {
* 判断是否还有元素存在
* @return
*/
public synchronized boolean hasNext(){
public boolean hasNext(){
boolean result = true;
if (index==0){
int nowIndex = index.get();
if (nowIndex == 0){
result = false;
}
return result;
@ -51,7 +61,7 @@ public class QueueDto<T> {
public int getIndex(){
return this.index;
return this.index.get();
}
}

@ -186,6 +186,11 @@ public class BeanUtil {
return set;
}
/**
* 扫描包路径并返回一个队列class
* @param packagePath
* @return
*/
public static QueueDto<Class> getQueueDto(String packagePath){
QueueDto<Class> classQueueDto = new QueueDto<>();
String separator = File.separator;

@ -0,0 +1,16 @@
package com.lq.jms.service;
/**
* @author qi
*/
public interface ProductService {
/**
* 发送队列消息
* @param topic 主题
* @param msg 消息内容
*/
void sendQueue(String topic,String msg);
}

@ -0,0 +1,25 @@
package com.lq.jms.service.impl;
import com.lq.jms.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
/**
* @author qi
*/
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private JmsTemplate jmsTemplate;
@Override
public void sendQueue(String topic, String msg) {
jmsTemplate.convertAndSend(topic,msg);
}
}

@ -13,7 +13,8 @@
<import resource="classpath:spring/spring-task.xml"></import>
<!-- spring 邮箱-->
<import resource="classpath:spring/spring-email.xml"></import>
<!-- 消息队列中间件 -->
<import resource="classpath:spring/spring-activitMq.xml"></import>
<!-- websocket -->
<!--<import resource="classpath:spring/spring-websocket.xml"/>-->
</beans>

@ -1,31 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.14.5.xsd
">
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory" >
<property name="brokerURL" value="tcp://localhost:61616"/>
<!-- ActivieMQ的连接工厂 -->
<bean id="targetConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory" >
<property name="brokerURL" value="tcp://127.0.0.1:61616"/>
</bean>
<!-- spring jms 为我们提供的连接池 获取一个连接工厂 -->
<bean id="connectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory" ref="targetConnectionFactory"/>
</bean>
<!-- 消息目的地 消息队列模式-->
<bean id="queueDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="SpringActiveMQMsg"/>
</bean>
<!-- jms 消息模版 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
<!-- 默认主题 -->
<property name="defaultDestination" ref="queueDestination"/>
<!-- true:消息队列模式 false:订阅发布模式 默认:true-->
<property name="pubSubNoLocal" value="true"/>
<!-- 发送超时-->
<property name="receiveTimeout" value="10000"/>
</bean>
</beans>

@ -1,20 +1,21 @@
package com.lq;
import com.github.jsonzou.jmockdata.JMockData;
import com.lq.cms.emun.BasicsPermissionKeyEnum;
import com.lq.cms.emun.StatusTypeEnum;
import com.lq.dao.SysLogDao;
import com.lq.dao.SysPermissionDao;
import com.lq.dao.SysResourceDao;
import com.lq.dao.SysUserDao;
import com.lq.entity.SysLog;
import com.lq.entity.SysPermission;
import com.lq.entity.SysResource;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class SysPermissionServiceTest extends BaseTest {
@ -24,9 +25,20 @@ public class SysPermissionServiceTest extends BaseTest {
private SysPermissionDao sysPermissionDao;
@Autowired
private SysResourceDao sysResourceDao;
@Autowired
private SysLogDao sysLogDao;
@Test
public void test1(){
int length = 1;
while (length>0){
SysLog sysLog = JMockData.mock(SysLog.class);
sysLog.setId(null);
sysLog.setStatus(StatusTypeEnum.STATUS_ACTIVITY_YES.getValue());
sysLogDao.save(sysLog);
length--;
}
}
@ -51,7 +63,7 @@ public class SysPermissionServiceTest extends BaseTest {
sysPermission.setUpdateTime(new Date());
sysPermission.setUpdateUserId(1L);
// sysPermissionList.add(sysPermission);
sysPermissionDao.save(sysPermission);
// sysPermissionDao.save(sysPermission);
}
});
//3.权限入库

@ -0,0 +1,25 @@
package com.lq.code.dto;
import org.junit.Test;
import static org.junit.Assert.*;
public class QueueDtoTest {
@Test
public void add() {
}
@Test
public void pop() {
}
@Test
public void hasNext() {
}
@Test
public void getIndex() {
}
}
Loading…
Cancel
Save