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

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

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

import java.util.Properties;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.SendResult;


public class ProducerClient {

    public static void main(String[] args) {
        Properties properties = new Properties();
        // ProducerId,代表一类Producer,请向MetaQ运维人员申请
        properties.put(PropertyKeyConst.ProducerId, "ProducerId1");
        properties.put(PropertyKeyConst.ProducerId, "ProducerId1");
        Producer producer = ONSFactory.createProducer(properties);
        producer.start();
        Message msg = new Message(//
            "TopicTestONS", // Topic, 请向ONS运维人员申请
            "TagA", // Tag, 相当于子Topic概念,应用可以自由设置,Consumer消费时,可以通过他来过滤消息
            "Hello ONS".getBytes()// 消息内容,二进制形式
                );
        SendResult sendResult = producer.send(msg);
        System.out.println(sendResult);
        producer.shutdown();
       
       

    }
}
TOP

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

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.