use of org.apache.rocketmq.redis.replicator.conf.Configure in project rocketmq-externals by apache.
the class RocketMQRedisReplicatorTest method open.
@Test
public void open() throws Exception {
Configure configure = new Configure(properties);
Replicator replicator = new RocketMQRedisReplicator(configure);
final RocketMQRedisProducer producer = new RocketMQRedisProducer(configure);
producer.open();
final AtomicInteger test = new AtomicInteger();
replicator.addEventListener(new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
if (event instanceof KeyValuePair<?, ?>) {
try {
boolean success = producer.send(event);
if (success) {
test.incrementAndGet();
}
} catch (Exception e) {
LOGGER.error("Fail to send KeyValuePair", e);
}
} else if (event instanceof Command) {
try {
boolean success = producer.send(event);
if (success) {
test.incrementAndGet();
}
} catch (Exception e) {
LOGGER.error("Fail to send command", e);
}
}
}
});
replicator.addCloseListener(new CloseListener() {
@Override
public void handle(Replicator replicator) {
producer.close();
}
});
replicator.open();
assertEquals(19, test.get());
}
use of org.apache.rocketmq.redis.replicator.conf.Configure in project rocketmq-externals by apache.
the class RocketMQRedisReplicator method main.
public static void main(String[] args) throws Exception {
Configure configure = new Configure();
Replicator replicator = new RocketMQRedisReplicator(configure);
final RocketMQRedisProducer producer = new RocketMQRedisProducer(configure);
producer.open();
replicator.addEventListener((r, e) -> {
try {
if (!producer.send(e)) {
LOGGER.error("Failed to send event[{}]", e);
}
} catch (Exception ex) {
LOGGER.error("Failed to send event[{}]", e, ex);
}
});
replicator.addCloseListener(r -> producer.close());
replicator.open();
}
Aggregations