Commit 618c2aaa authored by yanzg's avatar yanzg

身份证识别

parent 1cbe27b6
...@@ -15,4 +15,10 @@ public interface QueueService { ...@@ -15,4 +15,10 @@ public interface QueueService {
* @param req 保存队列服务 * @param req 保存队列服务
*/ */
void create(QueueVo req); void create(QueueVo req);
/**
* 保存接口请求日志
*
* @param req 保存队列服务
*/
void create(QueueVo req,boolean isAsync);
} }
...@@ -4,19 +4,26 @@ import com.yanzuoguang.mq.dao.BeanDao; ...@@ -4,19 +4,26 @@ import com.yanzuoguang.mq.dao.BeanDao;
import com.yanzuoguang.mq.service.QueueService; import com.yanzuoguang.mq.service.QueueService;
import com.yanzuoguang.mq.vo.QueueVo; import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.beans.factory.annotation.Autowired; import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/** /**
* 交换器服务类 * 交换器服务类
* *
* @author 颜佐光 * @author 颜佐光
*/ */
@Component @Component
public class QueueServiceImpl implements QueueService { public class QueueServiceImpl implements QueueService, Runnable {
private final BeanDao beanDao;
private final Queue<QueueVo> queue = new ConcurrentLinkedQueue<>();
private boolean isAsyncRun = false;
@Autowired public QueueServiceImpl(BeanDao beanDao) {
private BeanDao beanDao; this.beanDao = beanDao;
}
/** /**
* 保存接口请求日志 * 保存接口请求日志
...@@ -26,17 +33,37 @@ public class QueueServiceImpl implements QueueService { ...@@ -26,17 +33,37 @@ public class QueueServiceImpl implements QueueService {
*/ */
@Override @Override
public void create(QueueVo req) { public void create(QueueVo req) {
initBean(req); initBean(req, true);
}
@Override
public void create(QueueVo req, boolean isAsync) {
initBean(req, isAsync);
} }
/** /**
* 初始化实体 * 初始化实体
* *
* @param vo 实体相关信息 * @param vo 实体相关信息
* @param isAsync 是否异步
*/ */
private void initBean(QueueVo vo) { private void initBean(QueueVo vo, boolean isAsync) {
vo.check(); if (!isAsync) {
initBeanHandle(vo);
} else {
queue.add(vo);
if (isAsyncRun) {
return;
}
synchronized (this) {
isAsyncRun = true;
new Thread(this).start();
}
}
}
private void initBeanHandle(QueueVo vo) {
vo.check();
// 创建死信队列 // 创建死信队列
if (!StringHelper.isEmpty(vo.getDedQueueName())) { if (!StringHelper.isEmpty(vo.getDedQueueName())) {
beanDao.createQueue(vo.getDedQueueName()); beanDao.createQueue(vo.getDedQueueName());
...@@ -50,7 +77,6 @@ public class QueueServiceImpl implements QueueService { ...@@ -50,7 +77,6 @@ public class QueueServiceImpl implements QueueService {
beanDao.createBinding(vo.getDedExchangeName(), vo.getDedQueueName(), vo.getDedRouteKey()); beanDao.createBinding(vo.getDedExchangeName(), vo.getDedQueueName(), vo.getDedRouteKey());
} }
// 创建当前队列,并且绑定死信队列 // 创建当前队列,并且绑定死信队列
beanDao.createQueue(vo.getQueueName(), vo.getDedTime(), vo.getDedExchangeName(), vo.getDedRouteKey()); beanDao.createQueue(vo.getQueueName(), vo.getDedTime(), vo.getDedExchangeName(), vo.getDedRouteKey());
// 创建当前交换器 // 创建当前交换器
...@@ -58,4 +84,24 @@ public class QueueServiceImpl implements QueueService { ...@@ -58,4 +84,24 @@ public class QueueServiceImpl implements QueueService {
// 创建绑定队列 // 创建绑定队列
beanDao.createBinding(vo.getExchangeName(), vo.getQueueName(), vo.getRouteKey()); beanDao.createBinding(vo.getExchangeName(), vo.getQueueName(), vo.getRouteKey());
} }
@Override
public void run() {
while (!this.queue.isEmpty()) {
QueueVo vo = this.queue.poll();
try {
if (vo != null) {
initBeanHandle(vo);
}
} catch (Exception ex) {
this.queue.add(vo);
ex.printStackTrace();
ThreadHelper.sleep(5000);
}
}
synchronized (this) {
this.isAsyncRun = false;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment