系统环境参考上一篇的服务搭建 Dubbo 3.0.3 + Nacos 2.0.3 + Spring Boot 2.3.6.RELEASE 整合及使用时遇到的问题
参考本地的配置方式,将容器云环境的服务中的配置文件进行配置替换后,启动并没有想象的那么顺利,服务启动后程序出现如下错误。
2022-01-05 10:38:43.565 ERROR 1 --- [Report-thread-1] o.a.d.m.store.nacos.NacosMetadataReport : [DUBBO] Failed to put org.apache.dubbo.metadata.report.identifier.MetadataIdentifier@9d736c2 to nacos {"parameters":{"version":"1.0.0","side":"provider","interface":"org.apache.dubbo.metadata.MetadataService","group":"dubbo-demo-consumer","metadata-type":"remote","application":"dubbo-demo-consumer","dubbo":"2.0.2","release":"3.0.5","anyhost":"true","methods":"getExportedURLs,getAndListenInstanceMetadata,toURLs,serviceName,isMetadataServiceURL,getSubscribedURLs,version,getExportedServiceURLs,exportInstanceMetadata,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition,getInstanceMetadataChangedListenerMap","deprecated":"false","getAndListenInstanceMetadata.sent":"true","qos.enable":"false","generic":"false","getAndListenInstanceMetadata.1.callback":"true","revision":"3.0.5","delay":"0","getAndListenInstanceMetadata.return":"true","background":"false","dynamic":"true","executes":"100","qos.accept.foreign.ip":"false","connections":"1"},"canonicalName":"org.apache.dubbo.metadata.MetadataService","codeSource":"jar:file:/opt/ucp-intranet-api.jar!/BOOT-INF/lib/dubbo-3.0.5.jar!/","methods":[{"name":"serviceName","parameterTypes":[],"returnType":"java.lang.String","annotations":[]},{"name":"getExportedURLs","parameterTypes":["java.lang.String"],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getExportedURLs","parameterTypes":["java.lang.String","java.lang.String"],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getExportedURLs","parameterTypes":["java.lang.String","java.lang.String","java.lang.String"],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getExportedURLs","parameterTypes":["java.lang.String","java.lang.String","java.lang.String","java.lang.String"],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getExportedURLs"
,"parameterTypes":[],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getSubscribedURLs","parameterTypes":[],"returnType":"java.util.SortedSet\u003cjava.lang.String\u003e","annotations":[]},{"name":"getExportedServiceURLs","parameterTypes":[],"returnType":"java.util.Set\u003corg.apache.dubbo.common.URL\u003e","annotations":[]},{"name":"getMetadataInfo","parameterTypes":["java.lang.String"],"returnType":"org.apache.dubbo.metadata.MetadataInfo","annotations":[]},{"name":"getMetadataInfos","parameterTypes":[],"returnType":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.MetadataInfo\u003e","annotations":[]},{"name":"getServiceDefinition","parameterTypes":["java.lang.String"],"returnType":"java.lang.String","annotations":[]},{"name":"getServiceDefinition","parameterTypes":["java.lang.String","java.lang.String","java.lang.String"],"returnType":"java.lang.String","annotations":[]},{"name":"exportInstanceMetadata","parameterTypes":["java.lang.String"],"returnType":"void","annotations":[]},{"name":"getInstanceMetadataChangedListenerMap","parameterTypes":[],"returnType":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.InstanceMetadataChangedListener\u003e","annotations":[]},{"name":"getAndListenInstanceMetadata","parameterTypes":["java.lang.String","org.apache.dubbo.metadata.InstanceMetadataChangedListener"],"returnType":"java.lang.String","annotations":[]},{"name":"version","parameterTypes":[],"returnType":"java.lang.String","annotations":[]}],"types":[{"type":"void"},{"type":"org.apache.dubbo.metadata.MetadataInfo","properties":{"app":"java.lang.String","services":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.MetadataInfo.ServiceInfo\u003e","revision":"java.lang.String"}},{"type":"long[]","items":["long"]},{"type":"java.util.Map\u003cjava.lang.String,java.util.Map\u003cjava.lang.String,java.lang.String\u003e\u003e","items":["java.lang.String","java.util.Map\u003cjava.lang.String,java.lang.String\u003e"]},{"type":"org.apache.dubbo.metad
ata.InstanceMetadataChangedListener"},{"type":"java.util.Map\u003cjava.lang.String,java.lang.Object\u003e","items":["java.lang.String","java.lang.Object"]},{"type":"org.apache.dubbo.metadata.MetadataInfo.ServiceInfo","properties":{"path":"java.lang.String","protocol":"java.lang.String","name":"java.lang.String","params":"java.util.Map\u003cjava.lang.String,java.lang.String\u003e","version":"java.lang.String","group":"java.lang.String"}},{"type":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.InstanceMetadataChangedListener\u003e","items":["java.lang.String","org.apache.dubbo.metadata.InstanceMetadataChangedListener"]},{"type":"java.lang.Integer"},{"type":"int"},{"type":"long"},{"type":"java.util.SortedSet\u003cjava.lang.String\u003e","items":["java.lang.String"]},{"type":"java.util.Set\u003corg.apache.dubbo.common.URL\u003e","items":["org.apache.dubbo.common.URL"]},{"type":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.MetadataInfo\u003e","items":["java.lang.String","org.apache.dubbo.metadata.MetadataInfo"]},{"type":"org.apache.dubbo.common.url.component.URLParam","properties":{"hashCodeCache":"int","DEFAULT_KEY":"java.util.BitSet","enableCompressed":"boolean","VALUE":"java.lang.Integer[]","EXTRA_PARAMS":"java.util.Map\u003cjava.lang.String,java.lang.String\u003e","rawParam":"java.lang.String","KEY":"java.util.BitSet","METHOD_PARAMETERS":"java.util.Map\u003cjava.lang.String,java.util.Map\u003cjava.lang.String,java.lang.String\u003e\u003e"}},{"type":"org.apache.dubbo.common.URL","properties":{"hashCodeCache":"int","attributes":"java.util.Map\u003cjava.lang.String,java.lang.Object\u003e","urlAddress":"org.apache.dubbo.common.url.component.URLAddress","urlParam":"org.apache.dubbo.common.url.component.URLParam"}},{"type":"java.util.Map\u003cjava.lang.String,org.apache.dubbo.metadata.MetadataInfo.ServiceInfo\u003e","items":["java.lang.String","org.apache.dubbo.metadata.MetadataInfo.ServiceInfo"]},{"type":"java.lang.Integer[]","items":["java.lang.Integer"]},{"type":"boolean"},{"type":"org
.apache.dubbo.common.url.component.URLAddress","properties":{"port":"int","host":"java.lang.String"}},{"type":"java.lang.Object"},{"type":"java.lang.String"},{"type":"java.util.BitSet","properties":{"words":"long[]"}},{"type":"java.util.Map\u003cjava.lang.String,java.lang.String\u003e","items":["java.lang.String","java.lang.String"]}],"annotations":[]}, cause: publish nacos metadata failed, dubbo version: 3.0.5, current host: 172.16.72.172
java.lang.RuntimeException: publish nacos metadata failed
at org.apache.dubbo.metadata.store.nacos.NacosMetadataReport.storeMetadata(NacosMetadataReport.java:293) [dubbo-3.0.5.jar!/:3.0.5]
at org.apache.dubbo.metadata.store.nacos.NacosMetadataReport.doStoreProviderMetadata(NacosMetadataReport.java:169) [dubbo-3.0.5.jar!/:3.0.5]
at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.storeProviderMetadataTask(AbstractMetadataReport.java:261) [dubbo-3.0.5.jar!/:3.0.5]
at org.apache.dubbo.metadata.report.support.AbstractMetadataReport.lambda$storeProviderMetadata$0(AbstractMetadataReport.java:248) [dubbo-3.0.5.jar!/:3.0.5]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_261]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_261]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_261]
产生上述错误的原因是:(nacos服务未开启安全认证将不受到影响)
1、环境上开启了nacos 的安全认证
2、配置文件中未对 元数据配置中心进行安全配置
3、配置文件中未对 元数据配置中心进namespace 隔离配置
故这三种情况将会导致服务无法注册到nacos中,也无法从nacos中获取到provider提供的服务接口
解决方案:
对dubbo 的元数据中心( metadata-report)进行如下配置
dubbo:
# 配置元数据中心
metadata-report:
address: nacos://127.0.0.1:8848
username: test
password: 123456
# 配置 namespace,有namespace需要指定namespace
parameters:
namespace: 88b66463-1685-40b3-ba9c-7b25e526dcfb
# 配置 隔离组,有配置 group 的需要指定 group
group: ucp
写的不好,欢迎大佬们指正!!!