use of com.alibaba.rocketmq.client.producer.SendResult in project warn-report by saaavsaaa.
the class ProducerDouble method send.
public boolean send(final Message msg) {
if (producers.isEmpty()) {
System.out.println("case : Producer send error, reason : there isn't producer which could be used");
throw new IllegalArgumentException(" there isn't producer which could be used ! ");
}
DefaultMQProducer errorProducer = null;
for (DefaultMQProducer one : producers) {
try {
SendResult sendResult = one.send(msg);
System.out.println(String.format("==============ip : %s, send NamesrvAddr : %s, send key: %s, topic :%s", one.getClientIP(), one.getNamesrvAddr(), msg.getKeys(), msg.getTopic()));
if (sendResult != null && sendResult.getSendStatus() != SendStatus.SEND_OK) {
errorSendeds.add(msg);
}
} catch (Exception e) {
System.out.println("reason : producer send error" + e.getMessage());
if (errorProducer == null) {
errorProducer = one;
} else {
return false;
}
}
}
if (errorProducer != null) {
errorSendeds.add(msg);
}
return true;
}
use of com.alibaba.rocketmq.client.producer.SendResult in project warn-report by saaavsaaa.
the class ProducerSingle method repeat.
@Override
public void repeat() {
int poolSize = 1;
int delay = repeatDelay;
int period = repeatPeriod;
ScheduledExecutorService executor = Executors.newScheduledThreadPool(poolSize);
Runnable runnable = new Runnable() {
public void run() {
if (!errorSendeds.isEmpty()) {
for (Message one : errorSendeds) {
System.out.println(String.format("case : ProducerSingle repeat, ip : %s, send NamesrvAddr : %s, send key: %s, topic :%s", producer.getClientIP(), producer.getNamesrvAddr(), one.getKeys(), one.getTopic()));
try {
SendResult sendResult = producer.send(one);
if (sendResult != null && sendResult.getSendStatus() == SendStatus.SEND_OK) {
errorSendeds.remove(one);
System.out.println("error count : " + errorSendeds.size());
}
System.out.println("repeat count :" + repeatCount.incrementAndGet());
} catch (Exception e) {
System.out.println("reason : sendRepeat ProducerSingle send error" + e.getMessage());
System.out.println("repeat count :" + repeatCount.incrementAndGet());
}
}
}
}
};
executor.scheduleAtFixedRate(runnable, delay, period, TimeUnit.MILLISECONDS);
}
use of com.alibaba.rocketmq.client.producer.SendResult in project warn-report by saaavsaaa.
the class TestProcess method TestSend.
// sh mqadmin updateTopic -b 192.168.3.62 -n 192.168.3.62:9876 -t 'testTopic'
@Test
public void TestSend() throws MQClientException, InterruptedException, RemotingException, MQBrokerException {
final String address = "192.168.1.44:9876;192.168.1.45:9876";
final String producerGroup = "pg";
final String topic = "topicTest";
final String tag = "";
final String key = "aaa";
final String body = "it's body by aaa";
Producer producer = new Producer(address, producerGroup);
Message msg = Producer.buildMessage(topic, tag, key, body);
SendResult sendResult = producer.send(msg);
System.out.println(sendResult);
}
use of com.alibaba.rocketmq.client.producer.SendResult in project warn-report by saaavsaaa.
the class ProducerSingle method send.
@Override
public boolean send(final Message msg) {
SendResult sendResult = null;
try {
sendResult = producer.send(msg);
} catch (Exception e) {
System.out.println("reason : producer send error" + e.getMessage());
errorSendeds.add(msg);
System.out.println("error count : " + errorSendeds.size());
return false;
}
System.out.println(String.format("case : ProducerSingle send, ip : %s, send NamesrvAddr : %s, send key: %s, topic :%s", producer.getClientIP(), producer.getNamesrvAddr(), msg.getKeys(), msg.getTopic()));
if (sendResult != null && sendResult.getSendStatus() == SendStatus.SEND_OK) {
return true;
} else {
System.out.println(String.format("case : send result is %s, reason : producer send error", sendResult.getSendStatus().toString()));
errorSendeds.add(msg);
System.out.println("error count : " + errorSendeds.size());
return false;
}
}
use of com.alibaba.rocketmq.client.producer.SendResult in project incubator-skywalking by apache.
the class OnSuccessInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
activeSpan.setComponent(ComponentsDefine.ROCKET_MQ);
SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
if (sendStatus != SendStatus.SEND_OK) {
activeSpan.errorOccurred();
Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
}
ContextManager.continued(enhanceInfo.getContextSnapshot());
}
Aggregations