Package com.aliyun.openservices.ons.api

Examples of com.aliyun.openservices.ons.api.Message


        // 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);
View Full Code Here


        properties.put(PropertyKeyConst.AccessKey, "F0000043D88CB7EF4");
        properties.put(PropertyKeyConst.SecretKey, "F0000043D900F191F");
        Producer producer = ONSFactory.createProducer(properties);
        // 在发送消息前,必须调用start方法来启动Producer,只需调用一次即可。
        producer.start();
        Message msg = new Message( //
            // Message Topic
            "TopicTestONS",
            // Message Tag,
            // 可理解为Gmail中的标签,对消息进行再归类,方便Consumer指定过滤条件在ONS服务器过滤
            "TagA",
            // Message Body
            // 任何二进制形式的数据,ONS不做任何干预,需要Producer与Consumer协商好一致的序列化和反序列化方式
            "Hello ONS".getBytes());

        // 设置代表消息的业务关键属性,请尽可能全局唯一。
        // 以方便您在无法正常收到消息情况下,可通过ONS Console查询消息并补发。
        // 注意:不设置也不会影响消息正常收发
        msg.setKey("ORDERID_100");

        // 发送消息,只要不抛异常就是成功
        SendResult sendResult = producer.send(msg);
        System.out.println(sendResult);
View Full Code Here

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgsRMQList,
                ConsumeConcurrentlyContext contextRMQ) {
            MessageExt msgRMQ = msgsRMQList.get(0);
            Message msg = ONSUtil.msgConvert(msgRMQ);
            msg.setMsgID(msgRMQ.getMsgId());

            MessageListener listener = ConsumerImpl.this.subscribeTable.get(msg.getTopic());
            if (null == listener) {
                throw new ONSClientException("MessageListener is null");
            }

            final ConsumeContext context = new ConsumeContext();
View Full Code Here

        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ProducerId, "ProducerId1");
        TransactionProducer producer =
                ONSFactory.createTransactionProducer(properties, new LocalTransactionCheckerImpl());
        producer.start();
        Message msg = new Message("TopicTestONS", "TagA", "Hello ONS".getBytes());
        SendResult sendResult = producer.send(msg, new LocalTransactionExecuter() {
            @Override
            public TransactionStatus execute(Message msg, Object arg) {
                return TransactionStatus.CommitTransaction;
            }
View Full Code Here

        Properties properties = new Properties();
        // ProducerId,代表一类Producer,请向MetaQ运维人员申请
        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);
View Full Code Here

        Properties properties = new Properties();
        // ProducerId,代表一类Producer,请向MetaQ运维人员申请
        properties.put(PropertyKeyConst.ProducerId, "ProducerId1");
        OrderProducer producer = ONSFactory.createOrderProducer(properties);
        producer.start();
        Message msg = new Message(//
            "TopicTestONS", // Topic, 请向MetaQ运维人员申请
            "TagA", // Tag, 相当于子Topic概念,应用可以自由设置,Consumer消费时,可以通过他来过滤消息
            "Hello ONS".getBytes()// 消息内容,二进制形式
                );
        SendResult sendResult = producer.send(msg, new MessageQueueSelector() {
View Full Code Here

public class Producer {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("producer.xml");
        ProducerBean producer = (ProducerBean) ctx.getBean("producer");
        SendResult sendResult = producer.send(new Message("TopicTest", "tag", "Hello".getBytes()));
        System.out.println(sendResult);
    }
View Full Code Here

    class MessageListenerOrderlyImpl implements MessageListenerOrderly {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> arg0, ConsumeOrderlyContext arg1) {
            MessageExt msgRMQ = arg0.get(0);
            Message msg = ONSUtil.msgConvert(msgRMQ);
            msg.setMsgID(msgRMQ.getMsgId());

            MessageOrderListener listener = OrderConsumerImpl.this.subscribeTable.get(msg.getTopic());
            if (null == listener) {
                throw new ONSClientException("MessageOrderListener is null");
            }

            final ConsumeOrderContext context = new ConsumeOrderContext();
View Full Code Here

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgsRMQList,
                ConsumeConcurrentlyContext contextRMQ) {
            MessageExt msgRMQ = msgsRMQList.get(0);
            Message msg = ONSUtil.msgConvert(msgRMQ);
            msg.setMsgID(msgRMQ.getMsgId());

            MessageListener listener = ConsumerImpl.this.subscribeTable.get(msg.getTopic());
            if (null == listener) {
                throw new ONSClientException("MessageListener is null");
            }

            final ConsumeContext context = new ConsumeContext();
View Full Code Here

    class MessageListenerOrderlyImpl implements MessageListenerOrderly {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> arg0, ConsumeOrderlyContext arg1) {
            MessageExt msgRMQ = arg0.get(0);
            Message msg = ONSUtil.msgConvert(msgRMQ);
            msg.setMsgID(msgRMQ.getMsgId());

            MessageOrderListener listener = OrderConsumerImpl.this.subscribeTable.get(msg.getTopic());
            if (null == listener) {
                throw new ONSClientException("MessageOrderListener is null");
            }

            final ConsumeOrderContext context = new ConsumeOrderContext();
View Full Code Here

TOP

Related Classes of com.aliyun.openservices.ons.api.Message

Copyright © 2018 www.massapicom. 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.