use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class AsyncSendExceptionIT method testQueueIdBigThanQueueNum.
@Test
public void testQueueIdBigThanQueueNum() throws Exception {
int queueId = 100;
sendFail = false;
MessageQueue mq = new MessageQueue(topic, broker1Name, queueId);
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
producer.send(msg, mq, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
}
@Override
public void onException(Throwable throwable) {
sendFail = true;
}
});
int checkNum = 50;
while (!sendFail && checkNum > 0) {
checkNum--;
TestUtils.waitForMoment(100);
}
producer.shutdown();
assertThat(sendFail).isEqualTo(true);
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class SendMsgStatusCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook);
producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());
try {
producer.start();
String brokerName = commandLine.getOptionValue('b').trim();
int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;
producer.send(buildMessage(brokerName, 16));
for (int i = 0; i < count; i++) {
long begin = System.currentTimeMillis();
SendResult result = producer.send(buildMessage(brokerName, messageSize));
System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
producer.shutdown();
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class CLusterSendMsgRTCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
DefaultMQProducer producer = new DefaultMQProducer(rpcHook);
producer.setProducerGroup(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
producer.start();
ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();
HashMap<String, Set<String>> clusterAddr = clusterInfoSerializeWrapper.getClusterAddrTable();
Set<String> clusterNames = null;
long amount = !commandLine.hasOption('a') ? 50 : Long.parseLong(commandLine.getOptionValue('a').trim());
long size = !commandLine.hasOption('s') ? 128 : Long.parseLong(commandLine.getOptionValue('s').trim());
long interval = !commandLine.hasOption('i') ? 10 : Long.parseLong(commandLine.getOptionValue('i').trim());
boolean printAsTlog = commandLine.hasOption('p') && Boolean.parseBoolean(commandLine.getOptionValue('p').trim());
String machineRoom = !commandLine.hasOption('m') ? "noname" : commandLine.getOptionValue('m').trim();
if (commandLine.hasOption('c')) {
clusterNames = new TreeSet<String>();
clusterNames.add(commandLine.getOptionValue('c').trim());
} else {
clusterNames = clusterAddr.keySet();
}
if (!printAsTlog) {
System.out.printf("%-24s %-24s %-4s %-8s %-8s%n", "#Cluster Name", "#Broker Name", "#RT", "#successCount", "#failCount");
}
while (true) {
for (String clusterName : clusterNames) {
Set<String> brokerNames = clusterAddr.get(clusterName);
if (brokerNames == null) {
System.out.printf("cluster [%s] not exist", clusterName);
break;
}
for (String brokerName : brokerNames) {
Message msg = new Message(brokerName, getStringBySize(size).getBytes(MixAll.DEFAULT_CHARSET));
long start = 0;
long end = 0;
long elapsed = 0;
int successCount = 0;
int failCount = 0;
for (int i = 0; i < amount; i++) {
start = System.currentTimeMillis();
try {
producer.send(msg);
successCount++;
end = System.currentTimeMillis();
} catch (Exception e) {
failCount++;
end = System.currentTimeMillis();
}
if (i != 0) {
elapsed += end - start;
}
}
double rt = (double) elapsed / (amount - 1);
if (!printAsTlog) {
System.out.printf("%-24s %-24s %-8s %-16s %-16s%n", clusterName, brokerName, String.format("%.2f", rt), successCount, failCount);
} else {
System.out.printf(String.format("%s|%s|%s|%s|%s%n", getCurTime(), machineRoom, clusterName, brokerName, new BigDecimal(rt).setScale(0, BigDecimal.ROUND_HALF_UP)));
}
}
}
Thread.sleep(interval * 1000);
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQAdminExt.shutdown();
producer.shutdown();
}
}
use of org.apache.rocketmq.client.producer.DefaultMQProducer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
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-rocketmq-all-4.1.0-incubating by lirenzuo.
the class QueryMsgByIdSubCommand method execute.
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
DefaultMQProducer defaultMQProducer = new DefaultMQProducer("ReSendMsgById");
defaultMQProducer.setInstanceName(Long.toString(System.currentTimeMillis()));
try {
defaultMQAdminExt.start();
if (commandLine.hasOption('s')) {
if (commandLine.hasOption('u')) {
String unitName = commandLine.getOptionValue('u').trim();
defaultMQProducer.setUnitName(unitName);
}
defaultMQProducer.start();
}
final String msgIds = commandLine.getOptionValue('i').trim();
final String[] msgIdArr = StringUtils.split(msgIds, ",");
if (commandLine.hasOption('g') && commandLine.hasOption('d')) {
final String consumerGroup = commandLine.getOptionValue('g').trim();
final String clientId = commandLine.getOptionValue('d').trim();
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
pushMsg(defaultMQAdminExt, consumerGroup, clientId, msgId.trim());
}
}
} else if (commandLine.hasOption('s')) {
boolean resend = Boolean.parseBoolean(commandLine.getOptionValue('s', "false").trim());
if (resend) {
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
sendMsg(defaultMQAdminExt, defaultMQProducer, msgId.trim());
}
}
}
} else {
for (String msgId : msgIdArr) {
if (StringUtils.isNotBlank(msgId)) {
queryById(defaultMQAdminExt, msgId.trim());
}
}
}
} catch (Exception e) {
throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
} finally {
defaultMQProducer.shutdown();
defaultMQAdminExt.shutdown();
}
}
Aggregations