diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java index b9043ecc5c7..f4a49fbedb7 100644 --- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java +++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/Ls.java @@ -26,6 +26,8 @@ import org.apache.dubbo.rpc.model.ProviderModel; import java.util.Collection; +import java.util.Comparator; +import java.util.stream.Collectors; @Cmd( name = "ls", @@ -53,6 +55,11 @@ public String listProvider() { Collection providerModelList = frameworkModel.getServiceRepository().allProviderModels(); + // Fix: Originally, providers were stored in ConcurrentHashMap, Disordered display of servicekey list + providerModelList = providerModelList.stream() + .sorted(Comparator.comparing(ProviderModel::getServiceKey)) + .collect(Collectors.toList()); + TTable tTable = new TTable(new TTable.ColumnDefine[] { new TTable.ColumnDefine(TTable.Align.MIDDLE), new TTable.ColumnDefine(TTable.Align.MIDDLE) }); @@ -81,6 +88,11 @@ public String listConsumer() { Collection consumerModelList = frameworkModel.getServiceRepository().allConsumerModels(); + // Fix: Originally, consumers were stored in ConcurrentHashMap, Disordered display of servicekey list + consumerModelList = consumerModelList.stream() + .sorted(Comparator.comparing(ConsumerModel::getServiceKey)) + .collect(Collectors.toList()); + TTable tTable = new TTable(new TTable.ColumnDefine[] { new TTable.ColumnDefine(TTable.Align.MIDDLE), new TTable.ColumnDefine(TTable.Align.MIDDLE) });