-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
257 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 68 additions & 19 deletions
87
austin-cron/src/main/java/com/java3y/austin/cron/pending/CrowdBatchTaskPending.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,88 @@ | ||
package com.java3y.austin.cron.pending; | ||
|
||
import com.java3y.austin.cron.domain.CrowdInfoVo; | ||
import com.java3y.austin.support.pending.BatchPendingThread; | ||
import com.java3y.austin.support.pending.Pending; | ||
import cn.hutool.core.collection.CollUtil; | ||
import cn.hutool.core.map.MapUtil; | ||
import cn.hutool.core.thread.ExecutorBuilder; | ||
import cn.hutool.core.util.StrUtil; | ||
import com.google.common.collect.Lists; | ||
import com.java3y.austin.cron.constants.PendingConstant; | ||
import com.java3y.austin.cron.vo.CrowdInfoVo; | ||
import com.java3y.austin.service.api.domain.BatchSendRequest; | ||
import com.java3y.austin.service.api.domain.MessageParam; | ||
import com.java3y.austin.service.api.enums.BusinessCode; | ||
import com.java3y.austin.service.api.service.SendService; | ||
import com.java3y.austin.support.pending.AbstractLazyPending; | ||
import com.java3y.austin.support.pending.PendingParam; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableBeanFactory; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
/** | ||
* 批量处理任务信息 | ||
* 延迟批量处理人群信息 | ||
* 调用 batch 发送接口 进行消息推送 | ||
* | ||
* @author 3y | ||
*/ | ||
@Component | ||
@Slf4j | ||
public class CrowdBatchTaskPending extends Pending<CrowdInfoVo> { | ||
@Component | ||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) | ||
public class CrowdBatchTaskPending extends AbstractLazyPending<CrowdInfoVo> { | ||
|
||
@Override | ||
public void initAndStart(PendingParam pendingParam) { | ||
threadNum = pendingParam.getThreadNum() == null ? threadNum : pendingParam.getThreadNum(); | ||
queue = pendingParam.getQueue(); | ||
|
||
for (int i = 0; i < threadNum; ++i) { | ||
BatchPendingThread<CrowdInfoVo> batchPendingThread = new BatchPendingThread(); | ||
batchPendingThread.setPendingParam(pendingParam); | ||
batchPendingThread.setName("batchPendingThread-" + i); | ||
batchPendingThread.start(); | ||
} | ||
@Autowired | ||
private SendService sendService; | ||
|
||
public CrowdBatchTaskPending() { | ||
PendingParam<CrowdInfoVo> pendingParam = new PendingParam<>(); | ||
pendingParam.setNumThreshold(PendingConstant.NUM_THRESHOLD) | ||
.setQueue(new LinkedBlockingQueue(PendingConstant.QUEUE_SIZE)) | ||
.setTimeThreshold(PendingConstant.TIME_THRESHOLD) | ||
.setExecutorService(ExecutorBuilder.create() | ||
.setCorePoolSize(PendingConstant.CORE_POOL_SIZE) | ||
.setMaxPoolSize(PendingConstant.MAX_POOL_SIZE) | ||
.setWorkQueue(PendingConstant.BLOCKING_QUEUE) | ||
.setHandler(new ThreadPoolExecutor.CallerRunsPolicy()) | ||
.build()); | ||
this.pendingParam = pendingParam; | ||
} | ||
|
||
@Override | ||
public void doHandle(List<CrowdInfoVo> list) { | ||
log.info("theadName:{},doHandle:{}", Thread.currentThread().getName(), list.size()); | ||
public void doHandle(List<CrowdInfoVo> crowdInfoVos) { | ||
|
||
// 1. 如果参数相同,组装成同一个MessageParam发送 | ||
Map<Map<String, String>, String> paramMap = MapUtil.newHashMap(); | ||
for (CrowdInfoVo crowdInfoVo : crowdInfoVos) { | ||
String receiver = crowdInfoVo.getReceiver(); | ||
Map<String, String> vars = crowdInfoVo.getParams(); | ||
if (paramMap.get(vars) == null) { | ||
paramMap.put(vars, receiver); | ||
} else { | ||
String newReceiver = StringUtils.join(new String[]{ | ||
paramMap.get(vars), receiver}, StrUtil.COMMA); | ||
paramMap.put(vars, newReceiver); | ||
} | ||
} | ||
|
||
// 2. 组装参数 | ||
List<MessageParam> messageParams = Lists.newArrayList(); | ||
for (Map.Entry<Map<String, String>, String> entry : paramMap.entrySet()) { | ||
MessageParam messageParam = MessageParam.builder().receiver(entry.getValue()) | ||
.variables(entry.getKey()).build(); | ||
messageParams.add(messageParam); | ||
} | ||
|
||
// 3. 调用批量发送接口发送消息 | ||
BatchSendRequest batchSendRequest = BatchSendRequest.builder().code(BusinessCode.COMMON_SEND.getCode()) | ||
.messageParamList(messageParams) | ||
.messageTemplateId(CollUtil.getFirst(crowdInfoVos.iterator()).getMessageTemplateId()) | ||
.build(); | ||
sendService.batchSend(batchSendRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
austin-handler/src/main/java/com/java3y/austin/handler/config/PrototypeBeanConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.