Search in sources :

Example 1 with Configure

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());
}
Also used : Replicator(com.moilioncircle.redis.replicator.Replicator) RocketMQRedisProducer(org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer) URISyntaxException(java.net.URISyntaxException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Command(com.moilioncircle.redis.replicator.cmd.Command) CloseListener(com.moilioncircle.redis.replicator.CloseListener) Configure(org.apache.rocketmq.redis.replicator.conf.Configure) Event(com.moilioncircle.redis.replicator.event.Event) EventListener(com.moilioncircle.redis.replicator.event.EventListener) Test(org.junit.Test)

Example 2 with Configure

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();
}
Also used : RedisReplicator(com.moilioncircle.redis.replicator.RedisReplicator) AbstractReplicator(com.moilioncircle.redis.replicator.AbstractReplicator) RedisSocketReplicator(com.moilioncircle.redis.replicator.RedisSocketReplicator) Replicator(com.moilioncircle.redis.replicator.Replicator) Configure(org.apache.rocketmq.redis.replicator.conf.Configure) RocketMQRedisProducer(org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

Replicator (com.moilioncircle.redis.replicator.Replicator)2 URISyntaxException (java.net.URISyntaxException)2 Configure (org.apache.rocketmq.redis.replicator.conf.Configure)2 RocketMQRedisProducer (org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer)2 AbstractReplicator (com.moilioncircle.redis.replicator.AbstractReplicator)1 CloseListener (com.moilioncircle.redis.replicator.CloseListener)1 RedisReplicator (com.moilioncircle.redis.replicator.RedisReplicator)1 RedisSocketReplicator (com.moilioncircle.redis.replicator.RedisSocketReplicator)1 Command (com.moilioncircle.redis.replicator.cmd.Command)1 Event (com.moilioncircle.redis.replicator.event.Event)1 EventListener (com.moilioncircle.redis.replicator.event.EventListener)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1