Search in sources :

Example 1 with DefaultKeyValue

use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.

the class ActivemqSourceTaskTest method test.

// @Test
public void test() throws InterruptedException {
    KeyValue kv = new DefaultKeyValue();
    kv.put("activemqUrl", "tcp://112.74.48.251:6166");
    kv.put("destinationType", "queue");
    kv.put("destinationName", "test-queue");
    ActivemqSourceTask task = new ActivemqSourceTask();
    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);
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry)

Example 2 with DefaultKeyValue

use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.

the class DivideTaskByTopic method divideSinkTaskByTopic.

private List<KeyValue> divideSinkTaskByTopic(DbConnectorConfig dbConnectorConfig, TaskDivideConfig tdc) {
    List<KeyValue> config = new ArrayList<KeyValue>();
    int parallelism = tdc.getTaskParallelism();
    int id = -1;
    Set<String> topicRouteSet = ((SinkDbConnectorConfig) dbConnectorConfig).getWhiteTopics();
    Map<Integer, StringBuilder> taskTopicList = new HashMap<>();
    for (String topicName : topicRouteSet) {
        int ind = ++id % parallelism;
        if (!taskTopicList.containsKey(ind)) {
            taskTopicList.put(ind, new StringBuilder(topicName));
        } else {
            taskTopicList.get(ind).append(",").append(topicName);
        }
    }
    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_TOPIC_NAMES, taskTopicList.get(i).toString());
        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;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue)

Example 3 with DefaultKeyValue

use of io.openmessaging.internal.DefaultKeyValue 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, String> taskTopicList = new HashMap<>();
    Map<Integer, Map<String, Map<String, String>>> taskWhiteList = new HashMap<>();
    for (Map.Entry<String, String> entry : topicRouteMap.entrySet()) {
        int ind = ++id % parallelism;
        if (!taskWhiteList.containsKey(ind)) {
            taskWhiteList.put(ind, new HashMap<>());
        }
        String dbKey = entry.getKey().split("-")[0];
        String tableKey = entry.getKey().split("-")[1];
        taskTopicList.put(ind, tableKey);
        String filter = entry.getValue();
        Map<String, String> tableMap = new HashMap<>();
        tableMap.put(tableKey, filter);
        if (!taskWhiteList.get(ind).containsKey(dbKey)) {
            taskWhiteList.get(ind).put(dbKey, tableMap);
        } else {
            taskWhiteList.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_WHITE_LIST, JSONObject.toJSONString(taskWhiteList.get(i)));
        keyValue.put(Config.CONN_TOPIC_NAMES, 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;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue)

Example 4 with DefaultKeyValue

use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.

the class JdbcSourceConnectorTest 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);
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) Test(org.junit.Test)

Example 5 with DefaultKeyValue

use of io.openmessaging.internal.DefaultKeyValue in project rocketmq-externals by apache.

the class KafkaSourceConnector method taskConfigs.

@Override
public List<KeyValue> taskConfigs() {
    if (connectConfig == null) {
        return new ArrayList<KeyValue>();
    }
    log.info("Source Connector taskConfigs enter");
    List<KeyValue> configs = new ArrayList<>();
    int task_num = connectConfig.getInt(ConfigDefine.TASK_NUM);
    log.info("Source Connector taskConfigs: task_num:" + task_num);
    for (int i = 0; i < task_num; ++i) {
        KeyValue config = new DefaultKeyValue();
        config.put(ConfigDefine.BOOTSTRAP_SERVER, connectConfig.getString(ConfigDefine.BOOTSTRAP_SERVER));
        config.put(ConfigDefine.TOPICS, connectConfig.getString(ConfigDefine.TOPICS));
        config.put(ConfigDefine.GROUP_ID, connectConfig.getString(ConfigDefine.GROUP_ID));
        config.put(ConfigDefine.CONNECTOR_CLASS, connectConfig.getString(ConfigDefine.CONNECTOR_CLASS));
        config.put(ConfigDefine.SOURCE_RECORD_CONVERTER, connectConfig.getString(ConfigDefine.SOURCE_RECORD_CONVERTER));
        configs.add(config);
    }
    return configs;
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) ArrayList(java.util.ArrayList)

Aggregations

DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)32 KeyValue (io.openmessaging.KeyValue)27 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)8 List (java.util.List)7 HashMap (java.util.HashMap)4 Field (java.lang.reflect.Field)3 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)2 Map (java.util.Map)2 Set (java.util.Set)2 MongoSourceTask (org.apache.connect.mongo.connector.MongoSourceTask)2 ReplicaSet (org.apache.connect.mongo.replicator.ReplicaSet)2 ReplicaSetConfig (org.apache.connect.mongo.replicator.ReplicaSetConfig)2 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)2 TaskTopicInfo (org.apache.rocketmq.replicator.config.TaskTopicInfo)2 Before (org.junit.Before)2 RedisURI (com.moilioncircle.redis.replicator.RedisURI)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedList (java.util.LinkedList)1