Search in sources :

Example 1 with SendResult

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;
}
Also used : SendResult(com.alibaba.rocketmq.client.producer.SendResult) DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 2 with SendResult

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Message(com.alibaba.rocketmq.common.message.Message) SendResult(com.alibaba.rocketmq.client.producer.SendResult) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 3 with SendResult

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);
}
Also used : Producer(rocket.Producer) Message(com.alibaba.rocketmq.common.message.Message) SendResult(com.alibaba.rocketmq.client.producer.SendResult) Test(org.junit.Test)

Example 4 with 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;
    }
}
Also used : SendResult(com.alibaba.rocketmq.client.producer.SendResult) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 5 with SendResult

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());
}
Also used : SendResult(com.alibaba.rocketmq.client.producer.SendResult) SendStatus(com.alibaba.rocketmq.client.producer.SendStatus) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

SendResult (com.alibaba.rocketmq.client.producer.SendResult)5 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)3 Message (com.alibaba.rocketmq.common.message.Message)2 DefaultMQProducer (com.alibaba.rocketmq.client.producer.DefaultMQProducer)1 SendStatus (com.alibaba.rocketmq.client.producer.SendStatus)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo)1 Test (org.junit.Test)1 Producer (rocket.Producer)1