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);
}
}
}
}
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()));
}
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;
}
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);
}
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;
}
Aggregations