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;
}
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;
}
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);
}
}
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();
}
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);
}
}
}
}
Aggregations