Package com.alibaba.rocketmq.client.producer

Examples of com.alibaba.rocketmq.client.producer.DefaultMQProducer


        this.pullMessageService = new PullMessageService(this);

        this.rebalanceService = new RebalanceService(this);

        this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
        this.defaultMQProducer.resetClientConfig(clientConfig);

        log.info("created a new client fatory, FactoryIndex: {} ClinetID: {} {} {}",//
            this.factoryIndex, //
            this.clientId, //
View Full Code Here


/**
* Producer,发送消息
*/
public class Producer {
    public static void main(String[] args) throws MQClientException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");

        producer.start();

        String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };

        for (int i = 0; i < 1000; i++) {
            try {
                Message msg = new Message("TopicTest",// topic
                    tags[i % tags.length],// tag
                    "KEY" + i,// key
                    ("Hello RocketMQ " + i).getBytes()// body
                        );
                SendResult sendResult = producer.send(msg);
                System.out.println(sendResult);
            }
            catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
View Full Code Here

* Producer,发送顺序消息
*/
public class Producer {
    public static void main(String[] args) {
        try {
            MQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");

            producer.start();

            String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };

            for (int i = 0; i < 100; i++) {
                // 订单ID相同的消息要有序
                int orderId = i % 10;
                Message msg =
                        new Message("TopicTest", tags[i % tags.length], "KEY" + i,
                            ("Hello RocketMQ " + i).getBytes());

                SendResult sendResult = producer.send(msg, new MessageQueueSelector() {
                    @Override
                    public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
                        Integer id = (Integer) arg;
                        int index = id % mqs.size();
                        return mqs.get(index);
                    }
                }, orderId);

                System.out.println(sendResult);
            }

            producer.shutdown();
        }
        catch (MQClientException e) {
            e.printStackTrace();
        }
        catch (RemotingException e) {
View Full Code Here

public class ClientConfigTest {
    public static void main(String[] args) throws SocketException {
        MixAll.printObjectProperties(null, new ClientConfig());
        System.out.println("----------------------------------------------");
        MixAll.printObjectProperties(null, new DefaultMQProducer());
        System.out.println("----------------------------------------------");
        MixAll.printObjectProperties(null, new TransactionMQProducer());
        System.out.println("----------------------------------------------");
        MixAll.printObjectProperties(null, new DefaultMQPushConsumer());
        System.out.println("----------------------------------------------");
View Full Code Here

        this.pullMessageService = new PullMessageService(this);

        this.rebalanceService = new RebalanceService(this);

        this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
        this.defaultMQProducer.resetClientConfig(clientConfig);

        log.info("created a new client fatory, FactoryIndex: {} ClinetID: {} {} {}",//
            this.factoryIndex, //
            this.clientId, //
View Full Code Here

        this.pullMessageService = new PullMessageService(this);

        this.rebalanceService = new RebalanceService(this);

        this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
        this.defaultMQProducer.resetClientConfig(clientConfig);

        log.info("created a new client fatory, FactoryIndex: {} ClinetID: {} {} {}",//
            this.instanceIndex, //
            this.clientId, //
View Full Code Here

        this.pullMessageService = new PullMessageService(this);

        this.rebalanceService = new RebalanceService(this);

        this.defaultMQProducer = new DefaultMQProducer(MixAll.CLIENT_INNER_PRODUCER_GROUP);
        this.defaultMQProducer.resetClientConfig(clientConfig);

        log.info("created a new client fatory, FactoryIndex: {} ClinetID: {} {} {}",//
            this.instanceIndex, //
            this.clientId, //
View Full Code Here

    private final DefaultMQProducer defaultMQProducer;


    public ProducerImpl(final Properties properties) {
        super(properties);
        this.defaultMQProducer = new DefaultMQProducer();

        String producerGroup =
                properties.getProperty(PropertyKeyConst.ProducerId, "__ONS_PRODUCER_DEFAULT_GROUP");
        this.defaultMQProducer.setProducerGroup(producerGroup);
View Full Code Here

    private final DefaultMQProducer defaultMQProducer;


    public OrderProducerImpl(final Properties properties) {
        super(properties);
        this.defaultMQProducer = new DefaultMQProducer();

        String producerGroup =
                properties.getProperty(PropertyKeyConst.ProducerId, "__ONS_PRODUCER_DEFAULT_GROUP");
        this.defaultMQProducer.setProducerGroup(producerGroup);
View Full Code Here

import com.alibaba.rocketmq.common.message.Message;


public class Producer {
    public static void main(String[] args) throws MQClientException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
        producer.start();

        try {
            for (int i = 0; i < 6000000; i++) {
                Message msg = new Message("TopicFilter7",// topic
                    "TagA",// tag
                    "OrderID001",// key
                    ("Hello MetaQ").getBytes());// body

                msg.putUserProperty("SequenceId", String.valueOf(i));

                SendResult sendResult = producer.send(msg);
                System.out.println(sendResult);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        producer.shutdown();
    }
View Full Code Here

TOP

Related Classes of com.alibaba.rocketmq.client.producer.DefaultMQProducer

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.