use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AsyncSendExceptionIT method testSelectorThrowsException.
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
producer.send(msg, new MessageQueueSelector() {
@Override
public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
String str = null;
return list.get(str.length());
}
}, null, SendCallBackFactory.getSendCallBack());
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class AsyncSendExceptionIT method testSendMQNull.
@Test(expected = java.lang.NullPointerException.class)
public void testSendMQNull() throws Exception {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
MessageQueue messageQueue = null;
producer.send(msg, messageQueue, SendCallBackFactory.getSendCallBack());
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class OneWaySendExceptionIT method testSendSelectorNull.
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSendSelectorNull() throws Exception {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
MessageQueueSelector selector = null;
producer.sendOneway(msg, selector, 100);
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class OneWaySendExceptionIT method testSelectorThrowsException.
@Test(expected = org.apache.rocketmq.client.exception.MQClientException.class)
public void testSelectorThrowsException() throws Exception {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
producer.sendOneway(msg, new MessageQueueSelector() {
@Override
public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
String str = null;
return list.get(str.length());
}
}, null);
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq by apache.
the class CheckMsgSendRTCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQProducer producer = new DefaultMQProducer(rpcHook);
producer.setProducerGroup(Long.toString(System.currentTimeMillis()));
try {
producer.start();
long start = 0;
long end = 0;
long timeElapsed = 0;
boolean sendSuccess = false;
String topic = commandLine.getOptionValue('t').trim();
long amount = !commandLine.hasOption('a') ? 100 : Long.parseLong(commandLine.getOptionValue('a').trim());
long msgSize = !commandLine.hasOption('s') ? 128 : Long.parseLong(commandLine.getOptionValue('s').trim());
Message msg = new Message(topic, getStringBySize(msgSize).getBytes(MixAll.DEFAULT_CHARSET));
System.out.printf("%-32s %-4s %-20s %s%n", "#Broker Name", "#QID", "#Send Result", "#RT");
for (int i = 0; i < amount; i++) {
start = System.currentTimeMillis();
try {
producer.send(msg, new MessageQueueSelector() {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
int queueIndex = (Integer) arg % mqs.size();
MessageQueue queue = mqs.get(queueIndex);
brokerName = queue.getBrokerName();
queueId = queue.getQueueId();
return queue;
}
}, i);
sendSuccess = true;
end = System.currentTimeMillis();
} catch (Exception e) {
sendSuccess = false;
end = System.currentTimeMillis();
}
if (i != 0) {
timeElapsed += end - start;
}
System.out.printf("%-32s %-4s %-20s %s%n", brokerName, queueId, sendSuccess, end - start);
}
double rt = (double) timeElapsed / (amount - 1);
System.out.printf("Avg RT: %s%n", String.format("%.2f", rt));
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
producer.shutdown();
}
}
Aggregations