The consumer group[CID-TEST-CONSOLE] has been created before, specify another name please.
多次启动 ONSClient.createConsumer 相同的消费者重复创建导致问题.
是使用相同的消费者id,然后启动多个topic进行消费.因为consumer 的对象已经创建了.再次创建则报错.
Properties properties = new Properties();
properties.put(PropertyKeyConst.ConsumerId, consumerId);
properties.put(PropertyKeyConst.AccessKey, appKey);
properties.put(PropertyKeyConst.SecretKey, appSecret);
properties.put(PropertyKeyConst.OnsChannel, ONSChannel.CLOUD);
properties.put(PropertyKeyConst.MessageModel,PropertyValueConst.CLUSTERING);
Consumer consumer = ONSFactory.createConsumer(properties);
consumer.subscribe(topic, "*", new MessageListener() {
public Action consume(Message message, ConsumeContext context) {
//System.out.println("Receive: " + message);
System.out.println("Receive: " + new String(message.getBody()));
return Action.CommitMessage;
}
});
consumer.start();
Consumer consumer2 = ONSFactory.createConsumer(properties);
consumer2.subscribe("TEST-CONSOLE-COMPANYDETAIL", "*", new MessageListener() {
public Action consume(Message message, ConsumeContext context) {
//System.out.println("Receive: " + message);
System.out.println("companyDetail Receive: " + new String(message.getBody()));
return Action.CommitMessage;
}
});
consumer2.start();
=============================
修改成则正常
Properties properties = new Properties();
properties.put(PropertyKeyConst.ConsumerId, consumerId);
properties.put(PropertyKeyConst.AccessKey, appKey);
properties.put(PropertyKeyConst.SecretKey, appSecret);
properties.put(PropertyKeyConst.OnsChannel, ONSChannel.CLOUD);
properties.put(PropertyKeyConst.MessageModel,PropertyValueConst.CLUSTERING);
Consumer consumer = ONSFactory.createConsumer(properties);
consumer.subscribe(topic, "*", new MessageListener() {
public Action consume(Message message, ConsumeContext context) {
//System.out.println("Receive: " + message);
System.out.println("Receive: " + new String(message.getBody()));
return Action.CommitMessage;
}
});
consumer.subscribe("TEST-CONSOLE-COMPANYDETAIL", "*", new MessageListener() {
public Action consume(Message message, ConsumeContext context) {
//System.out.println("Receive: " + message);
System.out.println("companyDetail Receive: " + new String(message.getBody()));
return Action.CommitMessage;
}
});
consumer.start();