本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus类的典型用法代码示例。如果您正苦于以下问题:Java ConsumeConcurrentlyStatus类的具体用法?Java ConsumeConcurrentlyStatus怎么用?Java ConsumeConcurrentlyStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConsumeConcurrentlyStatus类属于com.alibaba.rocketmq.client.consumer.listener包,在下文中一共展示了ConsumeConcurrentlyStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
public static void main(String[] args){
DefaultMQPushConsumer consumer =
new DefaultMQPushConsumer("PushConsumer");
consumer.setNamesrvAddr("127.0.0.1:9876");
try {
//订阅PushTopic下Tag为push的消息
consumer.subscribe("PushTopic", "push");
//程序第一次启动从消息队列头取数据
consumer.setConsumeFromWhere(
ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(
new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(
List<MessageExt> list,
ConsumeConcurrentlyContext Context) {
Message msg = list.get(0);
System.out.println(msg.toString());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
}
);
consumer.start();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: main
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_4");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("TopicTest", "*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.println("Consumer Started.");
}
示例3: main
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");
String filterCode = MixAll.file2String("/home/admin/MessageFilterImpl.java");
consumer.subscribe("TopicFilter7", "com.alibaba.rocketmq.example.filter.MessageFilterImpl",
filterCode);
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.println("Consumer Started.");
}
示例4: consume
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
public void consume(String topic, String subExpression) throws MQClientException {
consumer.subscribe(topic, "*");
// consumer.subscribe(topic, "TagA || TagB");
// consumer.subscribe(topic, "*");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
for(MessageExt msg : msgs) {
if (msg.getTags() != null && msg.getTags().equals("TagA")) {
// 执行TagA的消费
}
else if (msg.getTags() != null && msg.getTags().equals("TagB")) {
// 执行TagB的消费
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
}
示例5: consumeMessage
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
// TODO Auto-generated method stub
for (MessageExt msg : msgs) {
byte[] body = msg.getBody();
if (body.length == 2 && body[0] == 0 && body[1] == 0) {
LOG.error("Young:Got the end signal");
_collector.emit("stop",new Values("stop"));
continue;
}
if (msg.getTopic().equals(RaceConfig.MqPayTopic)) {
return doPayTopic(body);
}else if (msg.getTopic().equals(RaceConfig.MqTaobaoTradeTopic)) {
putTaobaoTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
} else if (msg.getTopic().equals(RaceConfig.MqTmallTradeTopic)) {
putTmallTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}else {
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
示例6: consumeMessage
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
for (MessageExt msg : msgs) {
byte[] body = msg.getBody();
if (body.length == 2 && body[0] == 0 && body[1] == 0) {
LOG.error("Young:Got the end signal");
_collector.emit("stop",new Values("stop"));
continue;
}
if (msg.getTopic().equals(RaceConfig.MqPayTopic)) {
return doPayTopic(body);
}else if (msg.getTopic().equals(RaceConfig.MqTaobaoTradeTopic)) {
putTaobaoTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
} else if (msg.getTopic().equals(RaceConfig.MqTmallTradeTopic)) {
putTmallTradeToTair(body);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}else {
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
示例7: testScheduledMessageConsumer
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Before
public void testScheduledMessageConsumer() throws Exception {
// Instantiate message consumer
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ExampleConsumer");
// Subscribe topics
consumer.subscribe("TestTopic", "*");
// Register message listener
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> messages, ConsumeConcurrentlyContext context) {
for (MessageExt message : messages) {
// Print approximate delay time period
System.out.println("Receive message[msgId=" + message.getMsgId() + "] "
+ (System.currentTimeMillis() - message.getStoreTimestamp()) + "ms later");
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
// Launch consumer
consumer.start();
}
示例8: testBroadcastConsumer
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Before
public void testBroadcastConsumer() throws Exception {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("example_group_name");
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
// set to broadcast mode
consumer.setMessageModel(MessageModel.BROADCASTING);
consumer.subscribe("TopicTest", "TagA || TagC || TagD");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.printf("Broadcast Consumer Started.%n");
}
示例9: sendMqTags
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
/**
* 验证规则 并按照规则将数据 转发到对应的 队列中
*/
private ConsumeConcurrentlyStatus sendMqTags(Map<String, String> matchingMap, String MqTags,
String Mqbody)
{
// 验证是否有空值
String[] keys =
{ "Tag", "body", "Topic", "Tags" };
try
{
ForwardedHelp.outStr(matchingMap, keys);
}
catch (Exception e)
{
LOGGER.error(e.getMessage());
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
return equalsTag(matchingMap, MqTags, Mqbody);
}
示例10: equalsbody
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
/**
* 匹配 body 消息实体的验证
*
* @param matchingMap 注入的 匹配 规则 数据
* @param MqTags 当前消费的MQ Tags
* @param Mqbody 当前转发的 消息 实体
* @param Topic 需要转发到的 MQ Topic
* @return
*/
private ConsumeConcurrentlyStatus equalsbody(Map<String, String> matchingMap, String MqTags,
String Mqbody, String[] Topic)
{
// 匹配 body
if ("*".equals(matchingMap.get("body")))
{
// 不需要 匹配 Tag
return sendMq(matchingMap, Mqbody, Topic);
}
if (!ForwardedHelp.isContains(Mqbody, matchingMap.get("body")))
{
LOGGER.debug("body 匹配未成功 放弃该消息 消息内容是 " + MqTags);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
else
{
// 不需要 匹配 Tag
return sendMq(matchingMap, Mqbody, Topic);
}
}
示例11: sendMq
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
/**
* 将数据发送给MQ
* @param matchingMap 注入的配置数据
* @param Mqbody 当前消息的 实体
* @param Topic 转发的队列名称
*/
private ConsumeConcurrentlyStatus sendMq(Map<String, String> matchingMap, String Mqbody,
String[] Topic)
{
for (String topicval : Topic)
{
try
{
if (producer.send(topicval, matchingMap.get("Tags"), Mqbody) == null) { return ConsumeConcurrentlyStatus.RECONSUME_LATER; }
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
catch (UnsupportedEncodingException e)
{
LOGGER.error(" 异常 转发消息到MQ 失败 Tag= " + matchingMap.get("Topic") + " body= "
+ Mqbody, e);
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
示例12: consumeMessage
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Override
public ConsumeConcurrentlyStatus consumeMessage(String strBody, MessageExt msg,
ConsumeConcurrentlyContext context)
{
// TODO 待完善 日志系统
for (Map<String, String> map : matching)
{
Map<String, String> params = new HashMap<String, String>();
params.put("Topic", msg.getTopic());
params.put("Tags", msg.getTags());
if (externalCall == null) params.put("Body", strBody);
else params.put("Body", externalCall.MessageConsumer(strBody, msg, context));
return sendMqTags(map, msg.getTags(), params);
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
示例13: sendMqTags
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
/**
* 验证规则 并按照规则将数据 转发到对应的 队列中
*/
public static ConsumeConcurrentlyStatus sendMqTags(Map<String, String> matchingMap,
String MqTags, Map<String, String> params)
{
// 验证是否有空值
String[] keys =
{ "url" };
try
{
ForwardedHelp.outStr(matchingMap, keys);
}
catch (Exception e)
{
LOGGER.error(e.getMessage());
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
}
return equalsTag(matchingMap, MqTags, params);
}
示例14: equalsbody
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
/**
* 匹配 body 消息实体的验证
*
* @param matchingMap 注入的 匹配 规则 数据
* @param MqTags 当前消费的MQ Tags
* @param Mqbody 当前转发的 消息 实体
* @param Topic 需要转发到的 MQ Topic
* @return
*/
private static ConsumeConcurrentlyStatus equalsbody(Map<String, String> matchingMap,
String MqTags, String url, Map<String, String> params)
{
// 匹配 body
if ("*".equals(matchingMap.get("body")))
{
// 不需要 匹配 Tag
return sendMq(matchingMap, url, params);
}
if (!ForwardedHelp.isContains(params.get("body"), matchingMap.get("body")))
{
LOGGER.debug("body 匹配未成功 放弃该消息 消息内容是 " + MqTags);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
else
{
// 不需要 匹配 Tag
return sendMq(matchingMap, url, params);
}
}
示例15: testStartupTwice
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; //导入依赖的package包/类
@Test
public void testStartupTwice() throws MQClientException {
DefaultMQPushConsumer consumer = getConsumer("S_fundmng_demo_producer", "TopicTest-fundmng");
consumer.registerMessageListener(new MessageListenerConcurrently() {
public ConsumeConcurrentlyStatus consumeMessage(final List<MessageExt> msgs,
final ConsumeConcurrentlyContext context) {
System.out.println("Consumer1:" + JSON.toJSONString(msgs));
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
System.out.println("start 1");
consumer.start();
System.out.println("start 2");
LockSupport.park();
}