|
@@ -165,6 +165,7 @@ public class ProjectService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * @param parallelism 并行度
|
|
|
* @param projectRunningPrefix
|
|
|
* @param userId
|
|
|
* @param projectId
|
|
@@ -175,9 +176,9 @@ public class ProjectService {
|
|
|
* @param ogtPOList
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
- public void sendTaskMessage( String projectRunningPrefix, String userId, String projectId, String projectType, Long videoTime, Set<ScenePO> scenePOSet, VehiclePO vehiclePO, List<CameraPO> cameraPOList, List<OgtPO> ogtPOList) {
|
|
|
+ public void sendTaskMessage(int parallelism, String projectRunningPrefix, String userId, String projectId, String projectType, Long videoTime, Set<ScenePO> scenePOSet, VehiclePO vehiclePO, List<CameraPO> cameraPOList, List<OgtPO> ogtPOList) {
|
|
|
|
|
|
- final int[] messageNumber = {0};
|
|
|
+ final int[] messageNumber = CollectionUtil.createIntArray(0);
|
|
|
log.info("ProjectService--sendTaskMessage 项目 " + projectId + " 获得的包括的场景信息为:" + scenePOSet);
|
|
|
for (ScenePO scenePO : scenePOSet) {
|
|
|
String sceneId = scenePO.getId();
|
|
@@ -263,21 +264,17 @@ public class ProjectService {
|
|
|
} catch (JsonProcessingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- //4-5 将 projectId 作为 topic 名称,发送 task 信息到 kafka
|
|
|
+ //4-5 将 projectId 作为 topic 名称,根据 parallelism 分散发送 task 信息到 kafka
|
|
|
String finalTaskJson = taskJson;
|
|
|
stringRedisTemplate.opsForValue().set(taskMessagePrefix, finalTaskJson);
|
|
|
- kafkaTemplate.send(projectId, taskJson).addCallback(success -> {
|
|
|
+ kafkaTemplate.send(projectId, messageNumber[0] % parallelism, "", taskJson).addCallback(success -> {
|
|
|
// 消息发送到的topic
|
|
|
String topic = success.getRecordMetadata().topic();
|
|
|
// 消息发送到的分区
|
|
|
int partition = success.getRecordMetadata().partition();
|
|
|
// 消息在分区内的offset
|
|
|
long offset = success.getRecordMetadata().offset();
|
|
|
- log.info("------- ProjectConsumer 发送消息成功:\n"
|
|
|
- + "主题 topic 为:" + topic + "\n"
|
|
|
- + "分区 partition 为:" + partition + "\n"
|
|
|
- + "偏移量为:" + offset + "\n"
|
|
|
- + "消息体为:" + finalTaskJson);
|
|
|
+ log.info("------- ProjectConsumer 发送消息成功, 主题 topic 为:" + topic + " 分区 partition 为:" + partition + " 偏移量为:" + offset + " 消息体为:" + finalTaskJson);
|
|
|
}, failure -> log.error("------- 发送消息失败:" + failure.getMessage()));
|
|
|
messageNumber[0] = messageNumber[0] + 1;
|
|
|
});
|