Package com.aliyun.openservices.ons.demo

Source Code of com.aliyun.openservices.ons.demo.ConsumerTest

/***********************************************************
运行示例代码的前置条件:

通过下面两种方式可以引入依赖(任选一种)
    1、Maven方式引入依赖
        <dependency>
            <groupId>com.aliyun.openservices</groupId>
            <artifactId>ons-client</artifactId>
            <version>1.1.1</version>
        </dependency>

    2、下载依赖Jar包
        http://onsall.oss-cn-hangzhou.aliyuncs.com/aliyun-ons-client-java.tar.gz
       
注意:收发消息只能在阿里云ECS上进行
***********************************************************/

package com.aliyun.openservices.ons.demo;

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 ConsumerTest {

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ConsumerId, "CID_001");
        properties.put(PropertyKeyConst.AccessKey, "F0000043D88CB7EF4");
        properties.put(PropertyKeyConst.SecretKey, "F0000043D900F191F");
        Consumer consumer = ONSFactory.createConsumer(properties);
        consumer.subscribe("TopicTestONS", "*", new MessageListener() {

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

        consumer.start();

        System.out.println("Consumer Started");
    }
}
TOP

Related Classes of com.aliyun.openservices.ons.demo.ConsumerTest

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.