use of org.apache.inlong.manager.common.pojo.tubemq.AddTubeConsumeGroupRequest.GroupNameJsonSetBean in project incubator-inlong by apache.
the class CreateTubeGroupTaskListener method listen.
@Override
public ListenerResult listen(WorkflowContext context) throws WorkflowListenerException {
GroupResourceProcessForm form = (GroupResourceProcessForm) context.getProcessForm();
String groupId = form.getInlongGroupId();
log.info("try to create consumer group for groupId {}", groupId);
InlongGroupInfo groupInfo = groupService.get(groupId);
String topicName = groupInfo.getMqResourceObj();
int clusterId = Integer.parseInt(commonOperateService.getSpecifiedParam(Constant.CLUSTER_TUBE_CLUSTER_ID));
QueryTubeTopicRequest queryTubeTopicRequest = QueryTubeTopicRequest.builder().topicName(topicName).clusterId(clusterId).user(groupInfo.getCreator()).build();
// Query whether the tube topic exists
boolean topicExist = tubeMqOptService.queryTopicIsExist(queryTubeTopicRequest);
Integer tryNumber = reTryConfigBean.getMaxAttempts();
Long delay = reTryConfigBean.getDelay();
while (!topicExist && --tryNumber > 0) {
log.info("check whether the tube topic exists, try count={}", tryNumber);
try {
Thread.sleep(delay);
delay *= reTryConfigBean.getMultiplier();
topicExist = tubeMqOptService.queryTopicIsExist(queryTubeTopicRequest);
} catch (InterruptedException e) {
log.error("check the tube topic exists error", e);
}
}
AddTubeConsumeGroupRequest addTubeConsumeGroupRequest = new AddTubeConsumeGroupRequest();
addTubeConsumeGroupRequest.setClusterId(clusterId);
addTubeConsumeGroupRequest.setCreateUser(groupInfo.getCreator());
GroupNameJsonSetBean groupNameJsonSetBean = new GroupNameJsonSetBean();
groupNameJsonSetBean.setTopicName(topicName);
String consumeGroupName = "sort_" + topicName + "_group";
groupNameJsonSetBean.setGroupName(consumeGroupName);
addTubeConsumeGroupRequest.setGroupNameJsonSet(Collections.singletonList(groupNameJsonSetBean));
try {
tubeMqOptService.createNewConsumerGroup(addTubeConsumeGroupRequest);
} catch (Exception e) {
throw new WorkflowListenerException("create tube consumer group for groupId=" + groupId + " error", e);
}
log.info("finish to create consumer group for {}", groupId);
return ListenerResult.success();
}
Aggregations