use of io.openmessaging.KeyValue in project rocketmq-externals by apache.
the class DivideTaskByTopic method divideSourceTaskByTopic.
private List<KeyValue> divideSourceTaskByTopic(DbConnectorConfig dbConnectorConfig, TaskDivideConfig tdc) {
List<KeyValue> config = new ArrayList<KeyValue>();
int parallelism = tdc.getTaskParallelism();
int id = -1;
Map<String, String> topicRouteMap = ((SourceDbConnectorConfig) dbConnectorConfig).getWhiteTopics();
Map<Integer, Map<String, Map<String, String>>> taskTopicList = new HashMap<>();
for (Map.Entry<String, String> entry : topicRouteMap.entrySet()) {
int ind = ++id % parallelism;
if (!taskTopicList.containsKey(ind)) {
taskTopicList.put(ind, new HashMap<>());
}
String dbKey = entry.getKey().split("-")[0];
String tableKey = entry.getKey().split("-")[1];
String filter = entry.getValue();
Map<String, String> tableMap = new HashMap<>();
tableMap.put(tableKey, filter);
if (!taskTopicList.get(ind).containsKey(dbKey)) {
taskTopicList.get(ind).put(dbKey, tableMap);
} else {
taskTopicList.get(ind).get(dbKey).putAll(tableMap);
}
}
for (int i = 0; i < parallelism; i++) {
KeyValue keyValue = new DefaultKeyValue();
keyValue.put(Config.CONN_DB_IP, tdc.getDbUrl());
keyValue.put(Config.CONN_DB_PORT, tdc.getDbPort());
keyValue.put(Config.CONN_DB_USERNAME, tdc.getDbUserName());
keyValue.put(Config.CONN_DB_PASSWORD, tdc.getDbPassword());
keyValue.put(Config.CONN_DB_DATACENTER, tdc.getLocalDataCenter());
keyValue.put(Config.CONN_WHITE_LIST, JSONObject.toJSONString(taskTopicList.get(i)));
keyValue.put(Config.CONN_DATA_TYPE, tdc.getDataType());
keyValue.put(Config.CONN_SOURCE_RECORD_CONVERTER, tdc.getSrcRecordConverter());
keyValue.put(Config.CONN_DB_MODE, tdc.getMode());
config.add(keyValue);
}
return config;
}
use of io.openmessaging.KeyValue in project rocketmq-externals by apache.
the class JdbcSourceConnectorTest method verifyAndSetConfigTest.
@Test
public void verifyAndSetConfigTest() {
KeyValue keyValue = new DefaultKeyValue();
for (String requestKey : Config.REQUEST_CONFIG) {
assertEquals(connector.verifyAndSetConfig(keyValue), "Request config key: " + requestKey);
keyValue.put(requestKey, requestKey);
}
assertEquals(connector.verifyAndSetConfig(keyValue), "");
}
use of io.openmessaging.KeyValue in project rocketmq-externals by apache.
the class BaseJmsSourceConnectorTest method verifyAndSetConfigTest.
@Test
public void verifyAndSetConfigTest() {
KeyValue keyValue = new DefaultKeyValue();
for (String requestKey : Config.REQUEST_CONFIG) {
assertEquals(connector.verifyAndSetConfig(keyValue), "Request config key: " + requestKey);
keyValue.put(requestKey, requestKey);
}
assertEquals(connector.verifyAndSetConfig(keyValue), "");
}
use of io.openmessaging.KeyValue in project rocketmq-externals by apache.
the class RabbitmqSourceTaskTest method test.
// @Test
public void test() throws InterruptedException {
KeyValue kv = new DefaultKeyValue();
kv.put("rabbitmqUrl", "amqp://112.74.48.251:5672");
kv.put("rabbitmqUsername", "admin");
kv.put("rabbitmqPassword", "admin");
kv.put("destinationType", "queue");
kv.put("destinationName", "test-queue");
RabbitmqSourceTask task = new RabbitmqSourceTask();
task.start(kv);
for (int i = 0; i < 20; ) {
Collection<SourceDataEntry> sourceDataEntry = task.poll();
i = i + sourceDataEntry.size();
System.out.println(sourceDataEntry);
}
Thread.sleep(20000);
}
use of io.openmessaging.KeyValue in project rocketmq-externals by apache.
the class ActivemqConnectorTest method taskConfigsTest.
@Test
public void taskConfigsTest() {
assertEquals(connector.taskConfigs().get(0), null);
KeyValue keyValue = new DefaultKeyValue();
for (String requestKey : Config.REQUEST_CONFIG) {
keyValue.put(requestKey, requestKey);
}
connector.verifyAndSetConfig(keyValue);
assertEquals(connector.taskConfigs().get(0), keyValue);
}
Aggregations