diff --git a/src/main/java/io/qyi/e5/config/rabbitMQ/RabbitMQConfig.java b/src/main/java/io/qyi/e5/config/rabbitMQ/RabbitMQConfig.java index 4b0e651..a2ce2d2 100644 --- a/src/main/java/io/qyi/e5/config/rabbitMQ/RabbitMQConfig.java +++ b/src/main/java/io/qyi/e5/config/rabbitMQ/RabbitMQConfig.java @@ -84,6 +84,10 @@ public class RabbitMQConfig { public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setAcknowledgeMode(AcknowledgeMode.MANUAL); + factory.setConcurrentConsumers(1); + factory.setMaxConcurrentConsumers(20); + factory.setPrefetchCount(20); + factory.setConnectionFactory(connectionFactory); factory.setMessageConverter(new Jackson2JsonMessageConverter()); return factory; diff --git a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java index f062aaa..2fc606e 100644 --- a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java +++ b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java @@ -40,18 +40,7 @@ public class ListenerImpl { logger.info("消费者1开始处理消息: {},时间戳:{}" ,message,System.currentTimeMillis()); System.out.println("消费者1开始处理消息:"+System.currentTimeMillis()); int github_id = Integer.valueOf(new String(message.getBody())); - try { - Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", github_id)); - if (Outlook == null) { - logger.warn("未找到此用户,github_id: {}",github_id); - /*这里也发送ack,不然会照成队列堆积*/ - channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); - return; - } - outlookService.getMailList(Outlook); - } catch (Exception e) { - e.printStackTrace(); - } + Task.executeE5(github_id); channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); /*再次进行添加任务*/ Task.sendTaskOutlookMQ(github_id); diff --git a/src/main/java/io/qyi/e5/service/task/ITask.java b/src/main/java/io/qyi/e5/service/task/ITask.java index 78e7570..30a4f58 100644 --- a/src/main/java/io/qyi/e5/service/task/ITask.java +++ b/src/main/java/io/qyi/e5/service/task/ITask.java @@ -10,4 +10,6 @@ public interface ITask { void sendTaskOutlookMQ(int github_id); void sendTaskOutlookMQALL(); + void executeE5(int github_id); + } diff --git a/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java b/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java index 4cfa034..8544e3f 100644 --- a/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java +++ b/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java @@ -38,12 +38,12 @@ public class TaskImpl implements ITask { public void sendTaskOutlookMQ(int github_id) { Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", github_id)); if (Outlook == null) { - logger.warn("未找到此用户,github_id: {}",github_id); + logger.warn("未找到此用户,github_id: {}", github_id); return; } /*根据用户设置生成随机数*/ - String Expiration = getRandom( Outlook.getCronTimeRandomStart(),Outlook.getCronTimeRandomEnd()); - send(github_id,Expiration); + String Expiration = getRandom(Outlook.getCronTimeRandomStart(), Outlook.getCronTimeRandomEnd()); + send(github_id, Expiration); } @@ -55,20 +55,32 @@ public class TaskImpl implements ITask { while (iterator.hasNext()) { Outlook next = iterator.next(); /*根据用户设置生成随机数*/ - String Expiration = getRandom( next.getCronTimeRandomStart(),next.getCronTimeRandomEnd()); + String Expiration = getRandom(next.getCronTimeRandomStart(), next.getCronTimeRandomEnd()); send(next.getGithubId(), Expiration); } } + @Override + @Async + public void executeE5(int github_id) { + Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", github_id)); + if (Outlook == null) { + logger.warn("未找到此用户,github_id: {}", github_id); + return; + } + outlookService.getMailList(Outlook); + } + /** * 发送消息到队列 - * @Description: - * @param: * @param msg - * @param Expiration - * @return: void - * @Author: 落叶随风 - * @Date: 2020/4/16 - */ + * + * @param Expiration + * @Description: + * @param: * @param msg + * @return: void + * @Author: 落叶随风 + * @Date: 2020/4/16 + */ public void send(Object msg, String Expiration) { CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); @@ -82,14 +94,15 @@ public class TaskImpl implements ITask { /** * 生成随机数 - * @Description: - * @param: * @param start - * @param end - * @return: java.lang.String - * @Author: 落叶随风 - * @Date: 2020/4/16 - */ - public String getRandom(int start, int end){ + * + * @param end + * @Description: + * @param: * @param start + * @return: java.lang.String + * @Author: 落叶随风 + * @Date: 2020/4/16 + */ + public String getRandom(int start, int end) { Random r = new Random(); String Expiration = String.valueOf((r.nextInt(end - start + 1) + start) * 1000); return Expiration; diff --git a/src/test/java/io/qyi/e5/string/dome01.java b/src/test/java/io/qyi/e5/string/dome01.java index 8694502..be53f9a 100644 --- a/src/test/java/io/qyi/e5/string/dome01.java +++ b/src/test/java/io/qyi/e5/string/dome01.java @@ -42,14 +42,14 @@ public class dome01 { @Test public void r(){ for (int i = 0; i < 30; i++) { - System.out.println(getRandom(60,120)); + System.out.println(getRandom(3600,7200)); } } public String getRandom(int start, int end){ Random r = new Random(); - String Expiration = String.valueOf((r.nextInt(end-start +1) + start)); + String Expiration = String.valueOf((r.nextInt(end-start +1) + start) ); return Expiration; } }