mirror of
https://github.com/apache/rocketmq.git
synced 2026-08-30 18:10:44 +08:00
add different send examples
This commit is contained in:
@@ -18,6 +18,7 @@ package org.apache.rocketmq.example.quickstart;
|
||||
|
||||
import org.apache.rocketmq.client.exception.MQClientException;
|
||||
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||||
import org.apache.rocketmq.client.producer.SendCallback;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.common.message.Message;
|
||||
import org.apache.rocketmq.remoting.common.RemotingHelper;
|
||||
@@ -65,6 +66,39 @@ public class Producer {
|
||||
* Call send message to deliver message to one of brokers.
|
||||
*/
|
||||
SendResult sendResult = producer.send(msg);
|
||||
/*
|
||||
* There are different ways to send message, if you don't care about the send result,you can use this way
|
||||
* {@code
|
||||
* producer.sendOneway(msg);
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* if you want to get the send result in a synchronize way, you can use this send method
|
||||
* {@code
|
||||
* SendResult sendResult = producer.send(msg);
|
||||
* System.out.println(sendResult.toString());
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* if you want to get the send result in a asynchronize way, you can use this send method
|
||||
* {@code
|
||||
*
|
||||
* producer.send(msg, new SendCallback() {
|
||||
* @Override
|
||||
* public void onSuccess(SendResult sendResult) {
|
||||
* // do something
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public void onException(Throwable e) {
|
||||
* // do something
|
||||
* }
|
||||
*});
|
||||
*
|
||||
*}
|
||||
*/
|
||||
|
||||
System.out.printf("%s%n", sendResult);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user