Package com.aliyun.openservices.ons.example.normal

Source Code of com.aliyun.openservices.ons.example.normal.ConsumerClient

package com.aliyun.openservices.ons.example.normal;

import java.util.Properties;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;


public class ConsumerClient {

    public static void main(String[] args) {
        Properties properties = new Properties();
        // ProducerId,代表一类Consumer,请向ONS运维人员申请
        properties.put(PropertyKeyConst.ConsumerId, "jiangjinrong");
        Consumer consumer = ONSFactory.createConsumer(properties);
        consumer.subscribe("TopicTestONS", "*", new MessageListener() {

            @Override
            public Action consume(Message message, ConsumeContext context) {
                System.out.println("Receive: " + message);
                return Action.CommitMessage;
            }
        });

        consumer.start();
    }
}
TOP

Related Classes of com.aliyun.openservices.ons.example.normal.ConsumerClient

TOP
Copyright © 2018 www.massapi.com. 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.