Search in sources :

Example 6 with Message

use of com.alibaba.rocketmq.common.message.Message in project warn-report by saaavsaaa.

the class ProducerDouble method repeat.

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 sended : errorSendeds) {
                    for (DefaultMQProducer one : producers) {
                        System.out.println(String.format("===repeat==============ip : %s, send NamesrvAddr : %s, send key: %s, topic :%s", one.getClientIP(), one.getNamesrvAddr(), sended.getKeys(), sended.getTopic()));
                        sendRepeat(one, sended);
                    }
                }
            }
        }
    };
    executor.scheduleAtFixedRate(runnable, delay, period, TimeUnit.MILLISECONDS);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Message(com.alibaba.rocketmq.common.message.Message) DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer)

Example 7 with Message

use of com.alibaba.rocketmq.common.message.Message 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 8 with Message

use of com.alibaba.rocketmq.common.message.Message in project incubator-skywalking by apache.

the class MessageSendInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Message message = (Message) allArguments[2];
    ContextCarrier contextCarrier = new ContextCarrier();
    String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress);
    span.setComponent(ComponentsDefine.ROCKET_MQ);
    Tags.MQ_BROKER.set(span, (String) allArguments[0]);
    Tags.MQ_TOPIC.set(span, message.getTopic());
    SpanLayer.asMQ(span);
    SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3];
    StringBuilder properties = new StringBuilder(requestHeader.getProperties());
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        if (!StringUtil.isEmpty(next.getHeadValue())) {
            properties.append(next.getHeadKey());
            properties.append(NAME_VALUE_SEPARATOR);
            properties.append(next.getHeadValue());
            properties.append(PROPERTY_SEPARATOR);
        }
    }
    requestHeader.setProperties(properties.toString());
    if (allArguments[6] != null) {
        ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager.capture()));
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Message(com.alibaba.rocketmq.common.message.Message) SendMessageRequestHeader(com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 9 with Message

use of com.alibaba.rocketmq.common.message.Message 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 10 with Message

use of com.alibaba.rocketmq.common.message.Message in project warn-report by saaavsaaa.

the class TestRocketCluter method TestSend.

@Test
public void TestSend() throws MQClientException, InterruptedException, RemotingException, MQBrokerException {
    final String producerGroup = "pg";
    final String topic = "topicTest";
    final String tag = "";
    final String key = "aaa";
    final String body = "it's body by qqq";
    List<String> addresses = new ArrayList<String>();
    addresses.add("192.168.1.44:9876");
    addresses.add("192.168.1.45:9876");
    ProducerCluter producer = new ProducerCluter(addresses, producerGroup);
    Message msg = ProducerCluter.buildMessage(topic, tag, key, body);
    boolean sendResult = producer.send(msg);
    System.out.println(sendResult);
// Thread.sleep(1000*1000);
}
Also used : ProducerCluter(rocket.ProducerCluter) Message(com.alibaba.rocketmq.common.message.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Message (com.alibaba.rocketmq.common.message.Message)15 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)5 DefaultMQProducer (com.alibaba.rocketmq.client.producer.DefaultMQProducer)5 MQBrokerException (com.alibaba.rocketmq.client.exception.MQBrokerException)4 RemotingException (com.alibaba.rocketmq.remoting.exception.RemotingException)4 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)3 ConsumeConcurrentlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)3 ConsumeConcurrentlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)3 ConsumeOrderlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)3 ConsumeOrderlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)3 MessageListenerConcurrently (com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently)3 MessageListenerOrderly (com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly)3 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)3 SendResult (com.alibaba.rocketmq.client.producer.SendResult)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Test (org.junit.Test)2 SendMessageRequestHeader (com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader)1 ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1