Search in sources :

Example 1 with RedisEvent

use of org.apache.rocketmq.connect.redis.pojo.RedisEvent in project rocketmq-externals by apache.

the class RedisEventListener method onEvent.

@Override
public void onEvent(Replicator replicator, Event event) {
    if (isUsefulEvent(event)) {
        LOGGER.info("receive event: {}", event.getClass());
        RedisEvent redisEvent = new RedisEvent();
        redisEvent.setEvent(event);
        if (replicator != null) {
            redisEvent.setReplId(replicator.getConfiguration().getReplId());
            redisEvent.setReplOffset(replicator.getConfiguration().getReplOffset());
            redisEvent.setStreamDB(replicator.getConfiguration().getReplStreamDB());
        }
        boolean commitSuccess = commitWithRetry(redisEvent, this.config.getEventCommitRetryTimes(), this.config.getEventCommitRetryInterval());
        if (!commitSuccess) {
            LOGGER.error("redis listener commit event error.");
            try {
                this.processor.stop();
            } catch (IOException e) {
                LOGGER.error("processor stop error. {}", e);
            }
        }
    }
}
Also used : RedisEvent(org.apache.rocketmq.connect.redis.pojo.RedisEvent) IOException(java.io.IOException)

Example 2 with RedisEvent

use of org.apache.rocketmq.connect.redis.pojo.RedisEvent in project rocketmq-externals by apache.

the class RedisEventTest method test.

@Test
public void test() {
    RedisEvent redisEvent = new RedisEvent();
    redisEvent.setEvent(getKeyValuePair());
    redisEvent.setReplOffset(3926872L);
    redisEvent.setReplId("c18cece63c7b16851a6f387f52dbbb9eee07e46f");
    redisEvent.setStreamDB(0);
    Assert.assertEquals("c18cece63c7b16851a6f387f52dbbb9eee07e46f", redisEvent.getReplId());
    Assert.assertTrue(3926872L == redisEvent.getReplOffset());
    Assert.assertTrue(0 == redisEvent.getStreamDB());
    Assert.assertNotNull(redisEvent.getEvent());
    Assert.assertEquals(KeyStringValueString.class, redisEvent.getEvent().getClass());
    Assert.assertEquals("key", new String(((KeyStringValueString) redisEvent.getEvent()).getKey()));
    Assert.assertEquals("value", new String(((KeyStringValueString) redisEvent.getEvent()).getValue()));
}
Also used : RedisEvent(org.apache.rocketmq.connect.redis.pojo.RedisEvent) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) Test(org.junit.Test)

Example 3 with RedisEvent

use of org.apache.rocketmq.connect.redis.pojo.RedisEvent in project rocketmq-externals by apache.

the class ProcessorTest method getRedisEvent.

private RedisEvent getRedisEvent() {
    RedisEvent redisEvent = new RedisEvent();
    redisEvent.setEvent(getKeyValuePair());
    redisEvent.setReplOffset(3926872L);
    redisEvent.setReplId("c18cece63c7b16851a6f387f52dbbb9eee07e46f");
    redisEvent.setStreamDB(0);
    return redisEvent;
}
Also used : RedisEvent(org.apache.rocketmq.connect.redis.pojo.RedisEvent)

Example 4 with RedisEvent

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

Example 5 with RedisEvent

use of org.apache.rocketmq.connect.redis.pojo.RedisEvent in project rocketmq-externals by apache.

the class RedisSourceTaskTest method getRedisEvent.

private RedisEvent getRedisEvent() {
    RedisEvent redisEvent = new RedisEvent();
    KeyStringValueString event = new KeyStringValueString();
    event.setKey("key".getBytes());
    event.setValue("value".getBytes());
    event.setValueRdbType(RDB_TYPE_STRING);
    redisEvent.setEvent(event);
    redisEvent.setReplId("replId");
    redisEvent.setReplOffset(6000L);
    redisEvent.setStreamDB(0);
    return redisEvent;
}
Also used : RedisEvent(org.apache.rocketmq.connect.redis.pojo.RedisEvent) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)

Aggregations

RedisEvent (org.apache.rocketmq.connect.redis.pojo.RedisEvent)7 Test (org.junit.Test)4 IOException (java.io.IOException)3 KeyStringValueString (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)2 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)1 DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)1