|
|
@@ -41,8 +41,6 @@ public class AliyunRocketMqConsumer extends MqBaseConsumer { |
|
|
@Value("${spring.aliyunRocketmq.namesrvAddr}") |
|
|
@Value("${spring.aliyunRocketmq.namesrvAddr}") |
|
|
private String namesrvAddr; |
|
|
private String namesrvAddr; |
|
|
|
|
|
|
|
|
private static Consumer consumer = null; |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
@PostConstruct |
|
|
public void init() { |
|
|
public void init() { |
|
|
Properties properties = new Properties(); |
|
|
Properties properties = new Properties(); |
|
|
@@ -58,18 +56,21 @@ public class AliyunRocketMqConsumer extends MqBaseConsumer { |
|
|
// properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING); |
|
|
// properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING); |
|
|
// 广播订阅方式 |
|
|
// 广播订阅方式 |
|
|
// properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING); |
|
|
// properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING); |
|
|
consumer = ONSFactory.createConsumer(properties); |
|
|
|
|
|
|
|
|
|
|
|
consumer.subscribe(EnumMsgMqTopic.DEFAULT.getCode(), "*", new MessageListener() { //订阅多个 Tag |
|
|
|
|
|
public Action consume(Message message, ConsumeContext context) { |
|
|
|
|
|
System.out.println("Receive: " + message); |
|
|
|
|
|
doMessage(new String(message.getBody())); |
|
|
|
|
|
return Action.CommitMessage; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
consumer.start(); |
|
|
|
|
|
log.info(" aliyunrocketMq consumer start success! "+JSON.toJSONString(consumer)); |
|
|
|
|
|
|
|
|
for (EnumMsgMqTopic topic: EnumMsgMqTopic.values()) { |
|
|
|
|
|
Consumer consumer = ONSFactory.createConsumer(properties); |
|
|
|
|
|
consumer.subscribe(topic.getCode(), "*", new MessageListener() { //订阅多个 Tag |
|
|
|
|
|
public Action consume(Message message, ConsumeContext context) { |
|
|
|
|
|
System.out.println("Receive: " + message); |
|
|
|
|
|
doMessage(new String(message.getBody())); |
|
|
|
|
|
return Action.CommitMessage; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
consumer.start(); |
|
|
|
|
|
log.info(" aliyunrocketMq consumer start success! "+JSON.toJSONString(consumer)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |