Search in sources :

Example 1 with DefaultRedisEventProcessor

use of org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor 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 2 with DefaultRedisEventProcessor

use of org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor 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)

Example 3 with DefaultRedisEventProcessor

use of org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor in project rocketmq-externals by apache.

the class ProcessorTest method getProcessor.

private RedisEventProcessor getProcessor(Config config) {
    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) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)

Example 4 with DefaultRedisEventProcessor

use of org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor in project rocketmq-externals by apache.

the class ProcessorTest method testHandler.

@Test
public void testHandler() throws Exception {
    processor = getProcessor();
    DefaultRedisEventProcessor defaultRedisEventProcessor = (DefaultRedisEventProcessor) processor;
    RedisEvent event = new RedisEvent();
    event.setEvent(getKeyValuePair());
    event.setReplOffset(123L);
    event.setStreamDB(0);
    event.setReplId("asdfsdfa");
    defaultRedisEventProcessor.commit(event);
    KVEntry res = null;
    try {
        res = defaultRedisEventProcessor.poll();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(res);
    event.setEvent(getKVCommandPair());
    defaultRedisEventProcessor.commit(event);
    try {
        res = defaultRedisEventProcessor.poll();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertNotNull(res);
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) RedisEvent(org.apache.rocketmq.connect.redis.pojo.RedisEvent) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) IOException(java.io.IOException) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Aggregations

DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)4 DefaultRedisEventHandler (org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)3 RedisEventHandler (org.apache.rocketmq.connect.redis.handler.RedisEventHandler)3 IOException (java.io.IOException)2 Config (org.apache.rocketmq.connect.redis.common.Config)2 RedisEventProcessor (org.apache.rocketmq.connect.redis.processor.RedisEventProcessor)2 ByteBuffer (java.nio.ByteBuffer)1 RedisEntryConverter (org.apache.rocketmq.connect.redis.converter.RedisEntryConverter)1 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)1 RedisEvent (org.apache.rocketmq.connect.redis.pojo.RedisEvent)1 Test (org.junit.Test)1 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)1