Search in sources :

Example 6 with Config

use of org.apache.rocketmq.connect.redis.common.Config in project rocketmq-externals by apache.

the class RedisPositionConverterTest method getConfig.

private Config getConfig() {
    Config config = new Config();
    config.setRedisAddr("127.0.0.1");
    config.setRedisPort(6379);
    config.setRedisPassword("");
    config.setEventCommitRetryTimes(10);
    return config;
}
Also used : Config(org.apache.rocketmq.connect.redis.common.Config)

Example 7 with Config

use of org.apache.rocketmq.connect.redis.common.Config in project rocketmq-externals by apache.

the class RedisPositionConverterTest method test.

@Test
public void test() {
    JSONObject jsonObject = RedisPositionConverter.longToJson(10000L);
    long offset = jsonObject.getLong(RedisConstants.POSITION);
    Assert.assertEquals(10000L, offset);
    Config config = getConfig();
    ByteBuffer byteBuffer = ByteBuffer.wrap(jsonObject.toJSONString().getBytes());
    Long position = RedisPositionConverter.jsonToLong(byteBuffer);
    config.setPosition(position);
    Assert.assertEquals(10000L, (long) config.getPosition());
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Config(org.apache.rocketmq.connect.redis.common.Config) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with Config

use of org.apache.rocketmq.connect.redis.common.Config in project rocketmq-externals by apache.

the class RedisSourceTask method start.

@Override
public void start(KeyValue keyValue) {
    this.kvEntryConverter = new RedisEntryConverter();
    this.config = new Config();
    this.config.load(keyValue);
    LOGGER.info("task config msg: {}", this.config.toString());
    // get position info
    ByteBuffer byteBuffer = this.context.positionStorageReader().getPosition(this.config.getPositionPartitionKey());
    Long position = RedisPositionConverter.jsonToLong(byteBuffer);
    if (position != null && position >= -1) {
        this.config.setPosition(position);
    }
    LOGGER.info("task load connector runtime position: {}", this.config.getPosition());
    this.eventProcessor = new DefaultRedisEventProcessor(config);
    RedisEventHandler eventHandler = new DefaultRedisEventHandler(this.config);
    this.eventProcessor.registEventHandler(eventHandler);
    this.eventProcessor.registProcessorCallback(new DefaultRedisEventProcessorCallback());
    try {
        this.eventProcessor.start();
        LOGGER.info("Redis task start.");
    } catch (IOException e) {
        LOGGER.error("processor start error: {}", e);
        this.stop();
    }
}
Also used : RedisEntryConverter(org.apache.rocketmq.connect.redis.converter.RedisEntryConverter) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) Config(org.apache.rocketmq.connect.redis.common.Config) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) IOException(java.io.IOException) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) ByteBuffer(java.nio.ByteBuffer)

Example 9 with Config

use of org.apache.rocketmq.connect.redis.common.Config in project rocketmq-externals by apache.

the class ListenerTest method testEventListenerRetry2.

@Test
public void testEventListenerRetry2() {
    Config config = getConfig();
    RedisEventProcessor processor = getExceptionProcessor(config);
    EventListener eventListener = new RedisEventListener(config, processor);
    KeyValuePair pair = new KeyStringValueString();
    eventListener.onEvent(null, pair);
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) Config(org.apache.rocketmq.connect.redis.common.Config) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) EventListener(com.moilioncircle.redis.replicator.event.EventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) Test(org.junit.Test)

Example 10 with Config

use of org.apache.rocketmq.connect.redis.common.Config in project rocketmq-externals by apache.

the class ListenerTest method getProcessor.

private RedisEventProcessor getProcessor() {
    Config config = getConfig();
    RedisEventHandler eventHandler = new DefaultRedisEventHandler(config);
    RedisEventProcessor processor = new DefaultRedisEventProcessor(config);
    processor.registEventHandler(eventHandler);
    return processor;
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) Config(org.apache.rocketmq.connect.redis.common.Config) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)

Aggregations

Config (org.apache.rocketmq.connect.redis.common.Config)14 Test (org.junit.Test)7 DefaultRedisEventHandler (org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)5 RedisEventHandler (org.apache.rocketmq.connect.redis.handler.RedisEventHandler)5 KeyValuePair (com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair)4 ByteBuffer (java.nio.ByteBuffer)4 DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)4 KeyStringValueString (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)3 BatchedKeyValuePair (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyValuePair)3 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)3 RedisEventProcessor (org.apache.rocketmq.connect.redis.processor.RedisEventProcessor)3 RedisURI (com.moilioncircle.redis.replicator.RedisURI)2 EventListener (com.moilioncircle.redis.replicator.event.EventListener)2 BatchedKeyStringValueString (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString)2 RedisEventListener (org.apache.rocketmq.connect.redis.processor.RedisEventListener)2 JSONObject (com.alibaba.fastjson.JSONObject)1 GetSetCommand (com.moilioncircle.redis.replicator.cmd.impl.GetSetCommand)1 AuxField (com.moilioncircle.redis.replicator.rdb.datatype.AuxField)1 KeyStringValueList (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList)1 KeyValue (io.openmessaging.KeyValue)1