use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class MessageExceptionIT method testProducerSmoke.
@Test
public void testProducerSmoke() {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
SendResult sendResult = null;
try {
sendResult = producer.send(msg);
} catch (Exception e) {
}
assertThat(sendResult).isNotEqualTo(null);
assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class ChinaPropIT method testSend10kChinaPropMsg.
/**
* @since version3.4.6
*/
@Test
public void testSend10kChinaPropMsg() {
Message msg = MessageFactory.getRandomMessage(topic);
msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
SendResult sendResult = null;
try {
sendResult = producer.send(msg);
} catch (Exception e) {
}
assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class QueryMsgByIdSubCommand method sendMsg.
private void sendMsg(final DefaultMQAdminExt defaultMQAdminExt, final DefaultMQProducer defaultMQProducer, final String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
try {
MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
if (msg != null) {
// resend msg by id
System.out.printf("prepare resend msg. originalMsgId=%s", msgId);
SendResult result = defaultMQProducer.send(msg);
System.out.printf("%s", result);
} else {
System.out.printf("no message. msgId=%s", msgId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class MQClientAPIImplTest method testSendMessageOneWay_Success.
@Test
public void testSendMessageOneWay_Success() throws RemotingException, InterruptedException, MQBrokerException {
doNothing().when(remotingClient).invokeOneway(anyString(), any(RemotingCommand.class), anyLong());
SendResult sendResult = mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ONEWAY, new SendMessageContext(), defaultMQProducerImpl);
assertThat(sendResult).isNull();
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class Producer method main.
public static void main(String[] args) throws MQClientException, InterruptedException {
CommandLine commandLine = buildCommandline(args);
if (commandLine != null) {
String group = commandLine.getOptionValue('g');
String topic = commandLine.getOptionValue('t');
String tags = commandLine.getOptionValue('a');
String keys = commandLine.getOptionValue('k');
String msgCount = commandLine.getOptionValue('c');
DefaultMQProducer producer = new DefaultMQProducer(group);
producer.setInstanceName(Long.toString(System.currentTimeMillis()));
producer.start();
for (int i = 0; i < Integer.parseInt(msgCount); i++) {
try {
Message msg = new Message(topic, tags, keys, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.send(msg);
System.out.printf("%-8d %s%n", i, sendResult);
} catch (Exception e) {
e.printStackTrace();
Thread.sleep(1000);
}
}
producer.shutdown();
}
}
Aggregations