Java Code Examples for io.openmessaging.PullConsumer#attachQueue()

The following examples show how to use io.openmessaging.PullConsumer#attachQueue() . 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: ConsumerTester.java    From coding-snippets with MIT License 6 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.demo.DefaultPullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    //init offsets
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 2
Source File: ConsumerTester.java    From OpenMessageShaping with MIT License 6 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.demo.DefaultPullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    //init offsets
    offsets.put(queue, new HashMap<>());
    for (String topic : topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map : offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 3
Source File: V7ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v7.V7PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 4
Source File: V1ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v1.V1PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 5
Source File: ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.demo.DefaultPullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 6
Source File: V6ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v6.V6PullConsumerNoStr");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 7
Source File: V4ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v4.V4PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 8
Source File: V2ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v2.V2PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 9
Source File: V5ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v5.V5PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 10
Source File: V3ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init(){
    try {
        Class kvClass=Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue=(KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.v2.V2PullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer==null){
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue,topics);
    } catch (Exception e) {
        logger.error("please check the package name and class:",e);
    }

    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
            //"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}
 
Example 11
Source File: ConsumerTester.java    From coding-snippets with MIT License 5 votes vote down vote up
public void init() {
    //init consumer
    try {
        Class kvClass = Class.forName("io.openmessaging.demo.DefaultKeyValue");
        KeyValue keyValue = (KeyValue) kvClass.newInstance();
        keyValue.put("STORE_PATH", Constants.STORE_PATH);
        Class consumerClass = Class.forName("io.openmessaging.demo.DefaultPullConsumer");
        consumer = (PullConsumer) consumerClass.getConstructor(new Class[]{KeyValue.class}).newInstance(new Object[]{keyValue});
        if (consumer == null) {
            throw new InstantiationException("Init Producer Failed");
        }
        consumer.attachQueue(queue, topics);
    } catch (Exception e) {
        logger.error("please check the package name and class name:", e);
    }
    /**
     * init offsets,为了检验正确性和顺序。
     * key为本线程消费的queue/topic,
     * value为对应的线程和该线程发送的消息的偏移(key为线程名, value初始为0)。
     */
    offsets.put(queue, new HashMap<>());
    for (String topic: topics) {
        offsets.put(topic, new HashMap<>());
    }
    for (Map<String, Integer> map: offsets.values()) {
        for (int i = 0; i < Constants.PRO_NUM; i++) {
        	//"PRODUCER_i",即生产者线程名
            map.put(Constants.PRO_PRE + i, 0);
        }
    }
}