use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.
the class DivideTaskByQueue method divide.
@Override
public List<KeyValue> divide(Map<String, Set<TaskTopicInfo>> topicRouteMap, TaskDivideConfig tdc) {
List<KeyValue> config = new ArrayList<KeyValue>();
int parallelism = tdc.getTaskParallelism();
Map<Integer, List<TaskTopicInfo>> queueTopicList = new HashMap<Integer, List<TaskTopicInfo>>();
int id = -1;
for (String t : topicRouteMap.keySet()) {
for (TaskTopicInfo taskTopicInfo : topicRouteMap.get(t)) {
int ind = ++id % parallelism;
if (!queueTopicList.containsKey(ind)) {
queueTopicList.put(ind, new ArrayList<TaskTopicInfo>());
}
queueTopicList.get(ind).add(taskTopicInfo);
}
}
for (int i = 0; i < parallelism; i++) {
KeyValue keyValue = new DefaultKeyValue();
keyValue.put(TaskConfigEnum.TASK_STORE_ROCKETMQ.getKey(), tdc.getStoreTopic());
keyValue.put(TaskConfigEnum.TASK_SOURCE_ROCKETMQ.getKey(), tdc.getSourceNamesrvAddr());
keyValue.put(TaskConfigEnum.TASK_DATA_TYPE.getKey(), DataType.COMMON_MESSAGE.ordinal());
keyValue.put(TaskConfigEnum.TASK_TOPIC_INFO.getKey(), JSONObject.toJSONString(queueTopicList.get(i)));
keyValue.put(TaskConfigEnum.TASK_SOURCE_RECORD_CONVERTER.getKey(), tdc.getSrcRecordConverter());
keyValue.put(TaskConfigEnum.TASK_SOURCE_ACL_ENABLE.getKey(), String.valueOf(tdc.isSrcAclEnable()));
keyValue.put(TaskConfigEnum.TASK_SOURCE_ACCESS_KEY.getKey(), tdc.getSrcAccessKey());
keyValue.put(TaskConfigEnum.TASK_SOURCE_SECRET_KEY.getKey(), tdc.getSrcSecretKey());
config.add(keyValue);
}
return config;
}
use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.
the class RmqSourceReplicatorTest method testGenerateTopic.
@Test
public void testGenerateTopic() throws NoSuchFieldException {
RmqSourceReplicator rmqSourceReplicator = Mockito.spy(RmqSourceReplicator.class);
RmqConnectorConfig config = new RmqConnectorConfig();
KeyValue kv = new DefaultKeyValue();
kv.put(ConfigDefine.CONN_TOPIC_RENAME_FMT, "${topic}.replica");
config.validate(kv);
Field field = RmqSourceReplicator.class.getDeclaredField("replicatorConfig");
FieldSetter.setField(rmqSourceReplicator, field, config);
String dstTopic = rmqSourceReplicator.generateTargetTopic("dest");
assertThat(dstTopic).isEqualTo("dest.replica");
}
Aggregations