public static void main()

in ons-sample/src/main/java/org/apache/rocketmq/ons/sample/producer/SimpleOrderProducer.java [30:54]


    public static void main(String[] args) {
        Properties producerProperties = new Properties();
        producerProperties.setProperty(PropertyKeyConst.GROUP_ID, MQConfig.ORDER_GROUP_ID);
        producerProperties.setProperty(PropertyKeyConst.AccessKey, MQConfig.ACCESS_KEY);
        producerProperties.setProperty(PropertyKeyConst.SecretKey, MQConfig.SECRET_KEY);
        producerProperties.setProperty(PropertyKeyConst.NAMESRV_ADDR, MQConfig.NAMESRV_ADDR);
        OrderProducer producer = ONSFactory.createOrderProducer(producerProperties);
        producer.start();
        System.out.printf("Producer Started. %n");

        for (int i = 0; i < 10; i++) {
            Message msg = new Message(MQConfig.ORDER_TOPIC, MQConfig.TAG, "MQ send order message test".getBytes());
            String orderId = "biz_" + i % 10;
            msg.setKey(orderId);
            String shardingKey = String.valueOf(orderId);
            try {
                SendResult sendResult = producer.send(msg, shardingKey);
                assert sendResult != null;
                System.out.printf("Send mq timer message success! Topic is: %s msgId is: %s%n", MQConfig.TOPIC, sendResult.getMessageId());
            } catch (ONSClientException e) {
                System.out.printf("Send mq message failed. Topic is: %s%n", MQConfig.TOPIC);
                e.printStackTrace();
            }
        }
    }