Search in sources :

Example 1 with GroupEventSink

use of com.alibaba.otter.canal.sink.entry.group.GroupEventSink in project canal by alibaba.

the class CanalInstanceWithManager method initEventSink.

protected void initEventSink() {
    logger.info("init eventSink begin...");
    int groupSize = getGroupSize();
    if (groupSize <= 1) {
        eventSink = new EntryEventSink();
    } else {
        eventSink = new GroupEventSink(groupSize);
    }
    if (eventSink instanceof EntryEventSink) {
        ((EntryEventSink) eventSink).setFilterTransactionEntry(false);
        ((EntryEventSink) eventSink).setEventStore(getEventStore());
    }
    // if (StringUtils.isNotEmpty(filter)) {
    // AviaterRegexFilter aviaterFilter = new AviaterRegexFilter(filter);
    // ((AbstractCanalEventSink) eventSink).setFilter(aviaterFilter);
    // }
    logger.info("init eventSink end! \n\t load CanalEventSink:{}", eventSink.getClass().getName());
}
Also used : GroupEventSink(com.alibaba.otter.canal.sink.entry.group.GroupEventSink) EntryEventSink(com.alibaba.otter.canal.sink.entry.EntryEventSink)

Example 2 with GroupEventSink

use of com.alibaba.otter.canal.sink.entry.group.GroupEventSink in project canal by alibaba.

the class GroupEventSinkTest method testGroupTwo.

@Test
public void testGroupTwo() {
    final DummyEventStore eventStore = new DummyEventStore();
    final GroupEventSink eventSink = new GroupEventSink(3);
    eventSink.setFilterTransactionEntry(true);
    eventSink.setEventStore(eventStore);
    eventSink.start();
    ExecutorService executor = Executors.newFixedThreadPool(3);
    final CountDownLatch latch = new CountDownLatch(1);
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 1L + i)), address, "ljhtest1");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest1");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("one sink finished!");
            latch.countDown();
        }
    });
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 10L + i)), address, "ljhtest2");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 40L + i)), address, "ljhtest2");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("tow sink finished!");
            latch.countDown();
        }
    });
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 100; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest3");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("tow sink finished!");
            latch.countDown();
        }
    });
    try {
        latch.await();
        Thread.sleep(200L);
    } catch (InterruptedException e) {
    }
    eventSink.stop();
    executor.shutdownNow();
}
Also used : GroupEventSink(com.alibaba.otter.canal.sink.entry.group.GroupEventSink) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) DummyEventStore(com.alibaba.otter.canal.sink.stub.DummyEventStore) Test(org.junit.Test)

Example 3 with GroupEventSink

use of com.alibaba.otter.canal.sink.entry.group.GroupEventSink in project canal by alibaba.

the class GroupEventPaserTest method testMysqlWithMysql.

@Test
public void testMysqlWithMysql() {
    // MemoryEventStoreWithBuffer eventStore = new
    // MemoryEventStoreWithBuffer();
    // eventStore.setBufferSize(8196);
    GroupEventSink eventSink = new GroupEventSink(3);
    eventSink.setFilterTransactionEntry(false);
    eventSink.setEventStore(new DummyEventStore());
    eventSink.start();
    // 构造第一个mysql
    MysqlEventParser mysqlEventPaser1 = buildEventParser(3344);
    mysqlEventPaser1.setEventSink(eventSink);
    // 构造第二个mysql
    MysqlEventParser mysqlEventPaser2 = buildEventParser(3345);
    mysqlEventPaser2.setEventSink(eventSink);
    // 构造第二个mysql
    MysqlEventParser mysqlEventPaser3 = buildEventParser(3346);
    mysqlEventPaser3.setEventSink(eventSink);
    // 启动
    mysqlEventPaser1.start();
    mysqlEventPaser2.start();
    mysqlEventPaser3.start();
    try {
        Thread.sleep(30 * 10 * 1000L);
    } catch (InterruptedException e) {
    }
    mysqlEventPaser1.stop();
    mysqlEventPaser2.stop();
    mysqlEventPaser3.stop();
}
Also used : GroupEventSink(com.alibaba.otter.canal.sink.entry.group.GroupEventSink) MysqlEventParser(com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser) Test(org.junit.Test)

Aggregations

GroupEventSink (com.alibaba.otter.canal.sink.entry.group.GroupEventSink)3 Test (org.junit.Test)2 MysqlEventParser (com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser)1 EntryEventSink (com.alibaba.otter.canal.sink.entry.EntryEventSink)1 DummyEventStore (com.alibaba.otter.canal.sink.stub.DummyEventStore)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1