Message message = new Message(topicName, "sync,no tag".getBytes(Charset.defaultCharset())); SendResult result = producer.send(message); log.info("sync :{}\n", result);
Message hasTagMessage = new Message(topicName, "test_tag", "sync,has tag".getBytes(StandardCharsets.UTF_8)); result = producer.send(hasTagMessage); log.info("has tag{}\n", result);
Message hasTagAndKeysMessage = new Message(topicName, "test_tag", "test_keys", "sync,has tag and keys".getBytes(StandardCharsets.UTF_8)); result = producer.send(hasTagAndKeysMessage); log.info("has tag and key result:{}\n", result); }
异步发送消息
异步发送消息,在 send 方法执行之后程序会继续往下执行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
publicvoidasync()throws RemotingException, InterruptedException, MQClientException { Message message = new Message(topicName, "async, no tag".getBytes(StandardCharsets.UTF_8));