Search in sources :

Example 1 with DefaultMQProducer

use of com.yanghui.elephant.client.producer.DefaultMQProducer in project elephant by yanghuijava.

the class Producer method main.

public static void main(String[] args) throws MQClientException {
    DefaultMQProducer producer = new DefaultMQProducer("test");
    producer.setRegisterCenter("120.77.152.143:2181");
    producer.start();
    /**
     * 目前只支持activemq:
     * 发送queue,message的destination值加上前缀:queue://
     * 发送topic,message的destination值加上前缀:topic://
     */
    try {
        for (int i = 0; i < 1; i++) {
            Message msg = new Message("queue://yanghui.queue.test1", ("我是消息" + i).getBytes());
            SendResult sendResult = producer.send(msg);
            System.out.println(sendResult);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    producer.shutdown();
}
Also used : Message(com.yanghui.elephant.common.message.Message) SendResult(com.yanghui.elephant.client.producer.SendResult) DefaultMQProducer(com.yanghui.elephant.client.producer.DefaultMQProducer) MQClientException(com.yanghui.elephant.client.exception.MQClientException)

Aggregations

MQClientException (com.yanghui.elephant.client.exception.MQClientException)1 DefaultMQProducer (com.yanghui.elephant.client.producer.DefaultMQProducer)1 SendResult (com.yanghui.elephant.client.producer.SendResult)1 Message (com.yanghui.elephant.common.message.Message)1