denglifeng3 opened a new issue #3064:
URL: https://github.com/apache/rocketmq/issues/3064
Here is my code:
`
public static void main(String[] args) {
String nameAddress = "192.168.29.133:9876";
List<TopicModel> topicModels = null;
try {
MQAdminExt mqAdminExt = getMqAdminExt(nameAddress);
// createTopic("192.168.29.133:9876", "testTopic1");
//// TopicModel topicModel = getTopicInfo("192.168.29.133:9876",
"testTopic1", mqAdminExt);
//// System.out.println(topicModel);
ClusterInfo clusterInfo = getClusterInfo(mqAdminExt);
clusterInfo.getClusterAddrTable().values().forEach(clusterNames->clusterNames.forEach(clusterName->
{
try {
createTopic(nameAddress, "testTopic1", clusterName);
} catch (SubCommandException e) {
e.printStackTrace();
}
}));
// clusterInfo.getBrokerAddrTable().values().forEach(brokerData
-> {
// brokerData.getBrokerAddrs().values().forEach(broker->{
// try {
// createTopic(nameAddress, "testTopic1", broker);
// } catch (SubCommandException e) {
// e.printStackTrace();
// }
// });
// });
TopicModel topicModel = getTopicInfo(nameAddress, "testTopic1",
mqAdminExt);
System.out.println(topicModel);
closeMqAdminExt(mqAdminExt);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void createTopic(String namesrvAddr, String topicName, String
clusterName) throws SubCommandException {
UpdateTopicSubCommand updateTopicSubCommand = new
UpdateTopicSubCommand();
Options options = new Options();
options.addOption("n", "namesrvAddr", true, "");
CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " +
updateTopicSubCommand.commandName(), createTopicArgs(namesrvAddr, topicName,
clusterName), updateTopicSubCommand.buildCommandlineOptions(options),
new PosixParser());
updateTopicSubCommand.execute(commandLine, options, null);
}
public static String[] createTopicArgs(String namesrvAddr, String
topicName, String clusterName){
List<String> args = new ArrayList<>();
args.add("-n "+namesrvAddr);
args.add("-t "+topicName);
args.add("-r 2");
args.add("-w 2");
args.add("-c "+clusterName);
String[] strArr = new String[args.size()];
return args.toArray(strArr);
}`
I cannot create a topic with these code. it sade:
`org.apache.rocketmq.tools.command.SubCommandException:
UpdateTopicSubCommand command failed
at
org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand.execute(UpdateTopicSubCommand.java:181)
at test.queue.RocketMqUtil.createTopic(RocketMqUtil.java:160)
at test.queue.RocketMqUtil.lambda$null$0(RocketMqUtil.java:46)
at java.lang.Iterable.forEach(Iterable.java:75)
at test.queue.RocketMqUtil.lambda$main$1(RocketMqUtil.java:44)
at java.util.HashMap$Values.forEach(HashMap.java:981)
at test.queue.RocketMqUtil.main(RocketMqUtil.java:44)
Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException:
connect to <null> failed
at
org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:393)
at
org.apache.rocketmq.client.impl.MQClientAPIImpl.getBrokerClusterInfo(MQClientAPIImpl.java:1180)
at
org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.examineBrokerClusterInfo(DefaultMQAdminExtImpl.java:275)
at
org.apache.rocketmq.tools.admin.DefaultMQAdminExt.examineBrokerClusterInfo(DefaultMQAdminExt.java:222)
at
org.apache.rocketmq.tools.command.CommandUtil.fetchMasterAddrByClusterName(CommandUtil.java:83)
at
org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand.execute(UpdateTopicSubCommand.java:154)
... 6 more
org.apache.rocketmq.tools.command.SubCommandException: UpdateTopicSubCommand
command failed
at
org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand.execute(UpdateTopicSubCommand.java:181)
at test.queue.RocketMqUtil.createTopic(RocketMqUtil.java:160)
at test.queue.RocketMqUtil.lambda$null$2(RocketMqUtil.java:54)
at java.util.HashMap$Values.forEach(HashMap.java:981)
at test.queue.RocketMqUtil.lambda$main$3(RocketMqUtil.java:52)
at java.util.HashMap$Values.forEach(HashMap.java:981)
at test.queue.RocketMqUtil.main(RocketMqUtil.java:51)
Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException:
connect to <null> failed
at
org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:393)
at
org.apache.rocketmq.client.impl.MQClientAPIImpl.getBrokerClusterInfo(MQClientAPIImpl.java:1180)
at
org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl.examineBrokerClusterInfo(DefaultMQAdminExtImpl.java:275)
at
org.apache.rocketmq.tools.admin.DefaultMQAdminExt.examineBrokerClusterInfo(DefaultMQAdminExt.java:222)
at
org.apache.rocketmq.tools.command.CommandUtil.fetchMasterAddrByClusterName(CommandUtil.java:83)
at
org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand.execute(UpdateTopicSubCommand.java:154)
... 6 more
TopicModel{topicName='testTopic1', queueNums=2, queues=[Queue{queueId=0,
minOffset=0, maxOffset=0, lastUpdateTimestamp=0}, Queue{queueId=1, minOffset=0,
maxOffset=0, lastUpdateTimestamp=0}]}
10:22:22.374 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel:
close the connection to remote address[192.168.29.133:10909] result: true
10:22:22.375 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel:
close the connection to remote address[192.168.29.133:9876] result: true
Process finished with exit code 0
`
My question is:
`else if (commandLine.hasOption('c')) {
String clusterName = commandLine.getOptionValue('c').trim();
defaultMQAdminExt.start();
Set<String> masterSet =
CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
for (String addr : masterSet) {
defaultMQAdminExt.createAndUpdateTopicConfig(addr,
topicConfig);
System.out.printf("create topic to %s success.%n", addr);
}`
The rocket-tools code here , it always throw exception. I think there is no
nameServerAddress given.
By the way , when I try to create topic with brokeAddress, it is success.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]