Package com.alibaba.otter.canal.protocol

Examples of com.alibaba.otter.canal.protocol.Message


                case GET:
                    Get get = CanalPacket.Get.parseFrom(packet.getBody());
                    if (StringUtils.isNotEmpty(get.getDestination()) && StringUtils.isNotEmpty(get.getClientId())) {
                        clientIdentity = new ClientIdentity(get.getDestination(), Short.valueOf(get.getClientId()));
                        MDC.put("destination", clientIdentity.getDestination());
                        Message message = null;

                        //                        if (get.getAutoAck()) {
                        //                            if (get.getTimeout() == -1) {//是否是初始值
                        //                                message = embededServer.get(clientIdentity, get.getFetchSize());
                        //                            } else {
                        //                                TimeUnit unit = convertTimeUnit(get.getUnit());
                        //                                message = embededServer.get(clientIdentity, get.getFetchSize(), get.getTimeout(), unit);
                        //                            }
                        //                        } else {
                        if (get.getTimeout() == -1) {//是否是初始值
                            message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize());
                        } else {
                            TimeUnit unit = convertTimeUnit(get.getUnit());
                            message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize(), get.getTimeout(),
                                                                  unit);
                        }
                        //                        }

                        Packet.Builder packetBuilder = CanalPacket.Packet.newBuilder();
                        packetBuilder.setType(PacketType.MESSAGES);

                        Messages.Builder messageBuilder = CanalPacket.Messages.newBuilder();
                        messageBuilder.setBatchId(message.getId());
                        if (message.getId() != -1 && !CollectionUtils.isEmpty(message.getEntries())) {
                            for (Entry entry : message.getEntries()) {
                                messageBuilder.addMessages(entry.toByteString());
                            }
                        }
                        packetBuilder.setBody(messageBuilder.build().toByteString());
                        NettyUtils.write(ctx.getChannel(), packetBuilder.build().toByteArray(), null);// 输出数据
View Full Code Here


            events = getEvents(canalInstance.getEventStore(), start, batchSize, timeout, unit);

            if (CollectionUtils.isEmpty(events.getEvents())) {
                logger.debug("get successfully, clientId:{} batchSize:{} but result is null", new Object[] {
                        clientIdentity.getClientId(), batchSize });
                return new Message(-1, new ArrayList<Entry>()); // 返回空包,避免生成batchId,浪费性能
            } else {
                // 记录到流式信息
                Long batchId = canalInstance.getMetaManager().addBatch(clientIdentity, events.getPositionRange());
                List<Entry> entrys = Lists.transform(events.getEvents(), new Function<Event, Entry>() {

                    public Entry apply(Event input) {
                        return input.getEntry();
                    }
                });

                logger.info("get successfully, clientId:{} batchSize:{} real size is {} and result is [batchId:{} , position:{}]",
                            new Object[] { clientIdentity.getClientId(), batchSize, entrys.size(), batchId,
                                    events.getPositionRange() });
                // 直接提交ack
                ack(clientIdentity, batchId);
                return new Message(batchId, entrys);
            }
        }
    }
View Full Code Here

            }

            if (CollectionUtils.isEmpty(events.getEvents())) {
                logger.debug("getWithoutAck successfully, clientId:{} batchSize:{} but result is null", new Object[] {
                        clientIdentity.getClientId(), batchSize });
                return new Message(-1, new ArrayList<Entry>()); // 返回空包,避免生成batchId,浪费性能
            } else {
                // 记录到流式信息
                Long batchId = canalInstance.getMetaManager().addBatch(clientIdentity, events.getPositionRange());
                List<Entry> entrys = Lists.transform(events.getEvents(), new Function<Event, Entry>() {

                    public Entry apply(Event input) {
                        return input.getEntry();
                    }
                });

                logger.info("getWithoutAck successfully, clientId:{} batchSize:{}  real size is {} and result is [batchId:{} , position:{}]",
                            new Object[] { clientIdentity.getClientId(), batchSize, entrys.size(), batchId,
                                    events.getPositionRange() });
                return new Message(batchId, entrys);
            }

        }
    }
View Full Code Here

    public Message get(int batchSize) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.get(batchSize);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getting data from server:{}\n{}", currentConnector.getAddress(),
                            ExceptionUtils.getFullStackTrace(t));
                times++;
View Full Code Here

    public Message get(int batchSize, Long timeout, TimeUnit unit) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.get(batchSize, timeout, unit);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getting data from server:{}\n{}", currentConnector.getAddress(),
                            ExceptionUtils.getFullStackTrace(t));
                times++;
View Full Code Here

    public Message getWithoutAck(int batchSize) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.getWithoutAck(batchSize);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getWithoutAck data from server:{}\n{}",
                            currentConnector.getAddress(), ExceptionUtils.getFullStackTrace(t));
                times++;
View Full Code Here

    public Message getWithoutAck(int batchSize, Long timeout, TimeUnit unit) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.getWithoutAck(batchSize, timeout, unit);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getWithoutAck data from server:{}\n{}",
                            currentConnector.getAddress(), ExceptionUtils.getFullStackTrace(t));
                times++;
View Full Code Here

    public Message get(int batchSize) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.get(batchSize);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getting data from server:{}\n{}", currentConnector.getAddress(),
                            t);
                times++;
View Full Code Here

    public Message getWithoutAck(int batchSize) throws CanalClientException {
        int times = 0;
        while (times < retryTimes) {
            try {
                Message msg = currentConnector.getWithoutAck(batchSize);
                return msg;
            } catch (Throwable t) {
                logger.warn("something goes wrong when getWithoutAck data from server:{}\n{}",
                            currentConnector.getAddress(), t);
                times++;
View Full Code Here

        }
    }

    public Message get(int batchSize) throws CanalClientException {
        waitClientRunning();
        Message msg = getWithoutAck(batchSize);
        ack(batchSize);
        return msg;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.otter.canal.protocol.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.