Search in sources :

Example 1 with SendCallback

use of com.alibaba.middleware.race.mom.SendCallback in project alibaba-mom by younfor.

the class ProducerAsyncTest method main.

public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    Producer producer = (Producer) Class.forName("com.alibaba.middleware.race.mom.DefaultProducer").newInstance();
    producer.setGroupId("PG-test");
    producer.setTopic("T-test");
    producer.start();
    Message message = new Message();
    message.setBody("Hello MOM".getBytes());
    message.setProperty("area", "us");
    // 调用此方法,当前线程不阻塞
    producer.asyncSendMessage(message, new SendCallback() {

        @Override
        public void onResult(SendResult result) {
            if (result.getStatus().equals(SendStatus.SUCCESS)) {
                System.out.println("send success:" + result.getMsgId());
            }
        }
    });
}
Also used : Producer(com.alibaba.middleware.race.mom.Producer) Message(com.alibaba.middleware.race.mom.Message) SendResult(com.alibaba.middleware.race.mom.SendResult) SendCallback(com.alibaba.middleware.race.mom.SendCallback)

Aggregations

Message (com.alibaba.middleware.race.mom.Message)1 Producer (com.alibaba.middleware.race.mom.Producer)1 SendCallback (com.alibaba.middleware.race.mom.SendCallback)1 SendResult (com.alibaba.middleware.race.mom.SendResult)1