Java Code Examples for com.alibaba.rocketmq.common.MixAll#file2String()

The following examples show how to use com.alibaba.rocketmq.common.MixAll#file2String() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalFileOffsetStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffset() throws MQClientException {
    String content = MixAll.file2String(this.storePath);
    if (null == content || content.length() == 0) {
        return this.readLocalOffsetBak();
    } else {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        } catch (Exception e) {
            log.warn("readLocalOffset Exception, and try to correct", e);
            return this.readLocalOffsetBak();
        }

        return offsetSerializeWrapper;
    }
}
 
Example 2
Source File: LocalFileOffsetStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffsetBak() throws MQClientException {
    String content = MixAll.file2String(this.storePath + ".bak");
    if (content != null && content.length() > 0) {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        } catch (Exception e) {
            log.warn("readLocalOffset Exception", e);
            throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" //
                    + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), //
                    e);
        }
        return offsetSerializeWrapper;
    }

    return null;
}
 
Example 3
Source File: Consumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");
    String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java");
    consumer.subscribe("TopicFilter7", "com.alibaba.rocketmq.example.filter.MessageFilterImpl",
        filterCode);

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                ConsumeConcurrentlyContext context) {
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
Example 4
Source File: LocalFileOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffset() throws MQClientException {
    String content = MixAll.file2String(this.storePath);
    if (null == content || content.length() == 0) {
        return this.readLocalOffsetBak();
    } else {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        } catch (Exception e) {
            log.warn("readLocalOffset Exception, and try to correct", e);
            return this.readLocalOffsetBak();
        }

        return offsetSerializeWrapper;
    }
}
 
Example 5
Source File: LocalFileOffsetStore.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffsetBak() throws MQClientException {
    String content = MixAll.file2String(this.storePath + ".bak");
    if (content != null && content.length() > 0) {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        } catch (Exception e) {
            log.warn("readLocalOffset Exception", e);
            throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" //
                    + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), //
                    e);
        }
        return offsetSerializeWrapper;
    }

    return null;
}
 
Example 6
Source File: Consumer.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");

    String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java");
    consumer.subscribe("TopicFilter7", "com.alibaba.rocketmq.example.filter.MessageFilterImpl",
            filterCode);

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                                                        ConsumeConcurrentlyContext context) {
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
Example 7
Source File: LocalFileOffsetStore.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffset() throws MQClientException {
    String content = MixAll.file2String(this.storePath);
    if (null == content || content.length() == 0) {
        return this.readLocalOffsetBak();
    }
    else {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        }
        catch (Exception e) {
            log.warn("readLocalOffset Exception, and try to correct", e);
            return this.readLocalOffsetBak();
        }

        return offsetSerializeWrapper;
    }
}
 
Example 8
Source File: LocalFileOffsetStore.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
private OffsetSerializeWrapper readLocalOffsetBak() throws MQClientException {
    String content = MixAll.file2String(this.storePath + ".bak");
    if (content != null && content.length() > 0) {
        OffsetSerializeWrapper offsetSerializeWrapper = null;
        try {
            offsetSerializeWrapper =
                    OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class);
        }
        catch (Exception e) {
            log.warn("readLocalOffset Exception", e);
            throw new MQClientException(
                "readLocalOffset Exception, maybe fastjson version too low" //
                        + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), //
                e);
        }
        return offsetSerializeWrapper;
    }

    return null;
}
 
Example 9
Source File: KVConfigManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void load() {
    String content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath());
    if (content != null) {
        KVConfigSerializeWrapper kvConfigSerializeWrapper =
                KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class);
        if (null != kvConfigSerializeWrapper) {
            this.configTable.putAll(kvConfigSerializeWrapper.getConfigTable());
            log.info("load KV config table OK");
        }
    }
}
 
Example 10
Source File: KVConfigManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void load() {
    String content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath());
    if (content != null) {
        KVConfigSerializeWrapper kvConfigSerializeWrapper =
                KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class);
        if (null != kvConfigSerializeWrapper) {
            this.configTable.putAll(kvConfigSerializeWrapper.getConfigTable());
            log.info("load KV config table OK");
        }
    }
}
 
Example 11
Source File: KVConfigManager.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public void load() {
    String content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath());
    if (content != null) {
        KVConfigSerializeWrapper kvConfigSerializeWrapper =
                KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class);
        if (null != kvConfigSerializeWrapper) {
            this.configTable.putAll(kvConfigSerializeWrapper.getConfigTable());
            log.info("load KV config table OK");
        }
    }
}
 
Example 12
Source File: JDBCTransactionStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
private String createTableSql() {
    URL resource = JDBCTransactionStore.class.getClassLoader().getResource("transaction.sql");
    String fileContent = MixAll.file2String(resource);
    return fileContent;
}
 
Example 13
Source File: JDBCTransactionStore.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private String createTableSql() {
    URL resource = JDBCTransactionStore.class.getClassLoader().getResource("transaction.sql");
    String fileContent = MixAll.file2String(resource);
    return fileContent;
}
 
Example 14
Source File: JDBCTransactionStore.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
private String createTableSql() {
    URL resource = JDBCTransactionStore.class.getClassLoader().getResource("transaction.sql");
    String fileContent = MixAll.file2String(resource);
    return fileContent;
}