瀏覽代碼

消息发送

zouxuan 3 年之前
父節點
當前提交
69b55be856

+ 1 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMessageServiceImpl.java

@@ -309,7 +309,6 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 	}
 
 	@Override
-	@Async
 	public void batchSendMessage(Integer senderTenantId, MessageSender messageSender, MessageTypeEnum type, Map<Integer, String> receivers, Date triggerTime, Integer readStatus,
 			String url,String jpushType, Object... args) {
 		LOGGER.info("batchSendMessage tenantId {} msgSender {}, type {}, receivers {} ", senderTenantId, messageSender, type, receivers);
@@ -394,16 +393,11 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 	@Override
 	public void batchSendMessage(MessageSender messageSender, MessageTypeEnum type, Map<Integer, String> receivers, Date triggerTime, Integer readStatus,
 			String url,String jpushType, Object... args) {
-		ExecutorService executor = Executors.newFixedThreadPool(5);
-		CompletableFuture.runAsync(()->{
-			batchSendMessage(TenantContextHolder.getTenantId(), messageSender, type, receivers, triggerTime, readStatus, url, jpushType, args);
-		},executor);
-		executor.shutdown();
+		batchSendMessage(TenantContextHolder.getTenantId(), messageSender, type, receivers, triggerTime, readStatus, url, jpushType, args);
 	}
 
 
 	@Override
-	@Async
 	public void batchPushMessage(MessageTypeEnum type, Map<Integer, String> receivers, Date triggerTime, Integer readStatus,
 			String url,String jpushType,String sound,String channelId, Object... args) {
 		if (receivers == null || receivers.size() == 0) {
@@ -469,7 +463,6 @@ public class SysMessageServiceImpl extends BaseServiceImpl<Long, SysMessage> imp
 	}
 
 	@Override
-	@Async
 	public void sendMessage(MessageSender messageSender, Integer userId, String title, String content, String receiver, Date triggerTime, Integer readStatus, String url, String group,String jpushType) {
 		LOGGER.info("batchSendMessage {}, userId {}, receivers {} ", messageSender, userId, receiver);
 		if (StringUtils.isBlank(receiver)) {

+ 27 - 8
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/message/MessageSenderPluginContext.java

@@ -3,6 +3,9 @@ package com.ym.mec.thirdparty.message;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import com.ym.mec.thirdparty.entity.SysEmail;
 import com.ym.mec.thirdparty.message.provider.*;
@@ -65,10 +68,18 @@ public class MessageSenderPluginContext implements ApplicationContextAware {
 	 * @throws IOException
 	 */
 	public boolean send(MessageSender messageSender, String subject, String content, String receiver, String url, String jpushType,String sound,String channelId) throws Exception {
-
-		messageSenderPlugin = getMessageSenderPlugin(messageSender);
-
-		return messageSenderPlugin.send(subject, content, receiver, url, jpushType,sound,channelId);
+		ExecutorService executor = Executors.newFixedThreadPool(5);
+		CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(()->{
+			messageSenderPlugin = getMessageSenderPlugin(messageSender);
+			try {
+				return messageSenderPlugin.send(subject, content, receiver, url, jpushType,sound,channelId);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			return false;
+		},executor);
+		executor.shutdown();
+		return future.join();
 	}
 
 	/**
@@ -82,10 +93,18 @@ public class MessageSenderPluginContext implements ApplicationContextAware {
 	 * @throws IOException
 	 */
 	public boolean batchSend(MessageSender messageSender, String subject, String content, String[] receivers, String url, String jpushType,String sound,String channelId) throws Exception {
-
-		messageSenderPlugin = getMessageSenderPlugin(messageSender);
-
-		return messageSenderPlugin.batchSend(subject, content, receivers, url, jpushType,sound,channelId);
+		ExecutorService executor = Executors.newFixedThreadPool(5);
+		CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(()->{
+			messageSenderPlugin = getMessageSenderPlugin(messageSender);
+			try {
+				return messageSenderPlugin.batchSend(subject, content, receivers, url, jpushType,sound,channelId);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			return false;
+		},executor);
+		executor.shutdown();
+		return future.join();
 	}
 
 	@Override