Search in sources :

Example 11 with Message

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

the class Producer method buildMessage.

public static Message buildMessage(final String topic, final String tag, final String key, final String messageBody) {
    Message msg = new Message();
    msg.setTopic(topic);
    if (tag != null && tag.length() > 0) {
        msg.setTags(tag);
    }
    if (key != null && key.length() > 0) {
        msg.setKeys(key);
    }
    msg.setBody(messageBody.getBytes());
    return msg;
}
Also used : Message(com.alibaba.rocketmq.common.message.Message)

Example 12 with Message

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

the class ProducerCluter method buildMessage.

public static Message buildMessage(final String topic, final String tag, final String key, final String messageBody) {
    Message msg = new Message();
    msg.setTopic(topic);
    if (tag != null && tag.length() > 0) {
        msg.setTags(tag);
    }
    if (key != null && key.length() > 0) {
        msg.setKeys(key);
    }
    msg.setBody(messageBody.getBytes());
    return msg;
}
Also used : Message(com.alibaba.rocketmq.common.message.Message)

Example 13 with Message

use of com.alibaba.rocketmq.common.message.Message in project uavstack by uavorg.

the class RocketMQProducerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    String storeKey = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
    Span span = this.spanFactory.getSpanFromContext(storeKey);
    String spanMeta = this.spanFactory.getSpanMeta(span);
    Message msg = (Message) args[0];
    msg.putUserProperty(InvokeChainConstants.PARAM_MQHEAD_SPANINFO, spanMeta);
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        SlowOperContext slowOperContext = new SlowOperContext();
        String content;
        try {
            content = new String(msg.getBody(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            content = "unsupported encoding,defalut is utf-8.try to set ContentEncoding to fit.";
        }
        slowOperContext.put(SlowOperConstants.PROTOCOL_MQ_RABBIT_BODY, content);
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Message(com.alibaba.rocketmq.common.message.Message) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 14 with Message

use of com.alibaba.rocketmq.common.message.Message in project uavstack by uavorg.

the class TestRestService method testRocketmq.

@POST
@Path("testRocketmq")
public void testRocketmq(String jsonString) {
    DefaultMQProducer producer = new DefaultMQProducer("hookTest");
    producer.setNamesrvAddr("127.0.0.1:9876");
    Message msg = new Message("SELF_TEST_TOPIC", "test".getBytes());
    try {
        producer.start();
        for (int i = 0; i < 10; i++) {
            producer.send(msg);
        }
    } catch (MQClientException e) {
        e.printStackTrace();
    } catch (RemotingException e) {
        e.printStackTrace();
    } catch (MQBrokerException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    DefaultMQPushConsumer pushConsumer = new DefaultMQPushConsumer("hookTest");
    pushConsumer.setNamesrvAddr("127.0.0.1:9876");
    pushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    pushConsumer.registerMessageListener(new MessageListenerOrderly() {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            System.out.println("haha");
            return ConsumeOrderlyStatus.SUCCESS;
        }
    });
    pushConsumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            System.out.println("haha");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    try {
        pushConsumer.subscribe("SELF_TEST_TOPIC", null);
        pushConsumer.start();
    } catch (MQClientException e1) {
        e1.printStackTrace();
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    pushConsumer.shutdown();
    producer.shutdown();
}
Also used : MessageListenerConcurrently(com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently) Message(com.alibaba.rocketmq.common.message.Message) MessageListenerOrderly(com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly) MQBrokerException(com.alibaba.rocketmq.client.exception.MQBrokerException) ConsumeConcurrentlyStatus(com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus) DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer) ConsumeOrderlyContext(com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext) DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer) ConsumeConcurrentlyContext(com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext) MessageExt(com.alibaba.rocketmq.common.message.MessageExt) ConsumeOrderlyStatus(com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus) RemotingException(com.alibaba.rocketmq.remoting.exception.RemotingException) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 15 with Message

use of com.alibaba.rocketmq.common.message.Message in project uavstack by uavorg.

the class RocketMQProducer method send.

@Override
public void send(QueueInfo queueInfo, byte[] data) throws Exception {
    Map<String, String[]> topics = queueInfo.getTopics();
    Set<String> topicList = topics.keySet();
    for (String topicName : topicList) {
        String[] tagList = topics.get(topicName);
        // if there is no tag configuration, send only one message
        if (tagList.length == 0) {
            Message msg = new Message(topicName, data);
            producer.send(msg);
        } else // if there are tags configuration, send the messages to equal number of tags
        {
            for (String tags : tagList) {
                Message msg = new Message(topicName, tags, data);
                producer.send(msg);
            }
        }
    }
}
Also used : Message(com.alibaba.rocketmq.common.message.Message)

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