We all know rocketmq Send message with 3 Medium mode :
1, synchronization
     Send messages synchronously , You can get the results ,
 2,oneway mode
     This is the best way to send logs , such as , Fastest . This can be done .

3, asynchronous
     It's a bit of a misunderstanding , In fact, this also returns the result .
      You can see from the second screenshot , You need to implement the .

In fact , Whether it's synchronization , Or asynchronous ,broker metropolis response Relevant information came back . It's just that asynchrony requires an interface .
The following code I copy ons Of the code above :
public static void main(String[] args) {
Properties properties = new Properties();
properties.put(PropertyKeyConst.AccessKey, “DEMO_AK”);// AccessKey
Alicloud authentication , Create in Alibaba cloud server management console
properties.put(PropertyKeyConst.SecretKey, “DEMO_SK”);// SecretKey
Alicloud authentication , Create in Alibaba cloud server management console
properties.put(PropertyKeyConst.ProducerId, “DEMO_PID”);// You created Producer ID
“3000”);// Set send timeout , Unit millisecond
Producer producer = ONSFactory.createProducer(properties);
// Before sending a message , Must call start Method to start Producer, Just one call .
Message msg = new Message(
// Message Topic
// Message Tag, It can be understood as Gmail Tags in , Reclassify messages , convenient Consumer Specify filter conditions in MQ Server filtering
// Message Body, Any binary form of data ,MQ No intervention , need Producer And Consumer Negotiate a consistent way of serialization and deserialization
“Hello MQ”.getBytes());
// Set business critical properties on behalf of messages , Please be as global and unique as possible . In case you cannot receive the message normally , Available through MQ The console queries the message and reissues it .
// be careful : Do not set and will not affect the normal sending and receiving of messages
// Send message asynchronously , Send results through callback Return to client .
producer.sendAsync(msg, new SendCallback() {
public void onSuccess(final SendResult sendResult) {
// Consumption sent successfully
System.out.println(“send message success. topic=” + sendResult.getTopic() +
“, msgId=” + sendResult.getMessageId());
public void onException(OnExceptionContext context) {
// Message sending failed
System.out.println(“send message failed. topic=” + context.getTopic() + “,
msgId=” + context.getMessageId());
// stay callback Available before returning msgId.
System.out.println(“send message async. topic=” + msg.getTopic() + “, msgId=”
+ msg.getMsgID());
Before application exit , Destruction Producer object . be careful : If not destroyed
something the matter

    rocketmq send out Asynchronous messages and ons Almost , No more examples here

©2019-2020 Toolsou All rights reserved,
QCustomPlot series (5)- Real time dynamic curve python To solve the problem of dictionary writing list in GDOI2019 travels Java Basics ( Bubble sort )Unity Scene loading asynchronously ( Implementation of loading interface )" Cephalosporin wine Say go and go "? DANGER ! Don't drink alcohol when taking these drugs 2021 year 1 Monthly programmer salary statistics , average 14915 element Huawei certification HCIA-AI artificial intelligence java Simple lottery algorithm , luck draw DemoNOI2019 travels