use of com.alibaba.rocketmq.common.message.MessageExt in project uavstack by uavorg.
the class RocketMQPushConsumerAdapter method afterPreCap.
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
String storeKey = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
Span span = this.spanFactory.getSpanFromContext(storeKey);
if (span == null) {
return;
}
@SuppressWarnings("unchecked") List<MessageExt> exts = (List<MessageExt>) args[0];
String content;
try {
content = new String(exts.get(0).getBody(), "UTF-8");
} catch (UnsupportedEncodingException e) {
content = "unsupported encoding,defalut is utf-8.try to set ContentEncoding to fit.";
}
SlowOperContext slowOperContext = new SlowOperContext();
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.MessageExt in project uavstack by uavorg.
the class DoTestRocketmqProxy method main.
public static void main(String[] args) {
ConsoleLogger cl = new ConsoleLogger("test");
cl.setDebugable(true);
UAVServer.instance().setLog(cl);
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
RocketmqHookProxy p = new RocketmqHookProxy("test", Collections.emptyMap());
p.doInstallDProxy(null, "testApp");
DefaultMQProducer producer = new DefaultMQProducer("hookTest");
producer.setNamesrvAddr("127.0.0.1:9876");
try {
producer.start();
for (int i = 0; i < 100; i++) {
Message msg = new Message("SELF_TEST_TOPIC", (i + "").getBytes());
producer.send(msg);
}
} catch (MQClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemotingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MQBrokerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DefaultMQPushConsumer pushConsumer = new DefaultMQPushConsumer("hookTest1");
pushConsumer.setNamesrvAddr("127.0.0.1:9876");
pushConsumer.setMessageModel(MessageModel.BROADCASTING);
pushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
pushConsumer.registerMessageListener(new MessageListenerOrderly() {
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
System.out.println("Consumer1 " + count1++);
System.out.println(new String(msgs.get(0).getBody()));
// TODO Auto-generated method stub
return ConsumeOrderlyStatus.SUCCESS;
}
});
pushConsumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.println("Consumer1 " + count1++);
System.out.println(new String(msgs.get(0).getBody()));
// TODO Auto-generated method stub
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
try {
pushConsumer.subscribe("SELF_TEST_TOPIC", "*");
pushConsumer.start();
} catch (MQClientException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DefaultMQPushConsumer pushConsumer2 = new DefaultMQPushConsumer("hookTest2");
pushConsumer2.setNamesrvAddr("127.0.0.1:9876");
pushConsumer2.setMessageModel(MessageModel.BROADCASTING);
pushConsumer2.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
pushConsumer2.registerMessageListener(new MessageListenerOrderly() {
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
System.out.println("Consumer2 " + count2++);
System.out.println(new String(msgs.get(0).getBody()));
// TODO Auto-generated method stub
return ConsumeOrderlyStatus.SUCCESS;
}
});
pushConsumer2.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.println("Consumer2 " + count2++);
System.out.println(new String(msgs.get(0).getBody()));
// TODO Auto-generated method stub
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
try {
pushConsumer2.subscribe("SELF_TEST_TOPIC", "*");
pushConsumer2.start();
} catch (MQClientException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// pullConsumer.shutdown();
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.MessageExt 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("10.100.33.135: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("10.100.33.135: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.MessageExt in project warn-report by saaavsaaa.
the class PullConsumerCluter method getMessage.
public List<MessageExt> getMessage(final String topic, final Long offset, final String subExpression) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
List<MessageExt> result = new ArrayList<MessageExt>();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
for (MessageQueue mq : mqs) {
PullResult pullResult = consumer.pullBlockIfNotFound(mq, subExpression, offset, 1);
if (pullResult.getPullStatus() == PullStatus.FOUND) {
List<MessageExt> extList = pullResult.getMsgFoundList();
result.addAll(extList);
}
}
return result;
}
use of com.alibaba.rocketmq.common.message.MessageExt in project warn-report by saaavsaaa.
the class BusinessRun method exec.
@Override
public boolean exec(List<MessageExt> messages, ConsumeConcurrentlyContext Context) {
boolean result = true;
System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + messages);
for (MessageExt ext : messages) {
String key = ext.getKeys();
String keys = ext.getProperty("KEYS");
String value = new String(ext.getBody());
System.out.println("key : " + key + "; KEYS :" + keys + "; body : " + value);
}
return result;
}
Aggregations