dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

是否可以服务只消费其他服务,不需要启动提供者

Open clverhack opened this issue 3 years ago • 5 comments

如题:我的springboot 工程只想消费其他dubbo服务。但是不想启动自带的提供者。目前没找到是否可以禁用的方式。

这是我的工程配置: 下面日志启动了28080端口,实际我不想要它启用,我只需要消费服务就好 dubbo: enabled: true application: name: mst-dubbo-pay-consumer registry: id: yzlpay address: N/A register: false subscribe: true

2022-03-24 11:28:15.534 INFO 15420 --- [ main] o.a.dubbo.metadata.MappingCacheManager : [DUBBO] Successfully loaded mapping cache from file .mapping, entries 0, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.636 INFO 15420 --- [ main] org.apache.dubbo.config.ReferenceConfig : [DUBBO] Referred dubbo service: [com.mstdt.pay.nbopen.service.HotelListServiceInterface]. it's not GenericService reference, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.639 WARN 15420 --- [ main] o.a.d.r.client.metadata.MetadataUtils : [DUBBO] Remote Metadata Report Server not hasn't been configured or unavailable . Unable to get Metadata from remote!, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.650 INFO 15420 --- [ main] o.a.d.c.deploy.DefaultModuleDeployer : [DUBBO] Dubbo Module[1.1.1] has started., dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.652 INFO 15420 --- [ main] .c.m.ConfigurableMetadataServiceExporter : [DUBBO] Metadata Service Port hasn't been set will use default protocol defined in protocols., dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.652 INFO 15420 --- [ main] .c.m.ConfigurableMetadataServiceExporter : [DUBBO] Using dubbo protocol to export metadata service on port -1, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.673 WARN 15420 --- [ main] org.apache.dubbo.config.ServiceConfig : [DUBBO] Use random available port(20880) for protocol dubbo, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.713 INFO 15420 --- [ main] org.apache.dubbo.config.ServiceConfig : [DUBBO] Export dubbo service org.apache.dubbo.metadata.MetadataService to local registry url : injvm://127.0.0.1/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=mst-dubbo-pay-consumer&background=false&bind.ip=172.25.147.1&bind.port=20880&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=mst-dubbo-pay-consumer&interface=org.apache.dubbo.metadata.MetadataService&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15420&qos.enable=false&release=3.0.6&revision=3.0.6&side=provider&timestamp=1648092495670&version=1.0.0, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.714 INFO 15420 --- [ main] org.apache.dubbo.config.ServiceConfig : [DUBBO] Export dubbo service org.apache.dubbo.metadata.MetadataService to url dubbo://172.25.147.1:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=mst-dubbo-pay-consumer&background=false&bind.ip=172.25.147.1&bind.port=20880&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=mst-dubbo-pay-consumer&interface=org.apache.dubbo.metadata.MetadataService&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15420&qos.enable=false&release=3.0.6&revision=3.0.6&side=provider&timestamp=1648092495670&version=1.0.0, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.793 INFO 15420 --- [ main] **o.a.d.remoting.transport.AbstractServer : [DUBBO] Start NettyServer bind /0.0.0.0:20880, export /172.25.147.1:20880, dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.812 INFO 15420 --- [ main] .c.m.ConfigurableMetadataServiceExporter : [DUBBO] The MetadataService exports urls : [dubbo://172.25.147.1:20880/org.apache.dubbo.metadata.MetadataService?**anyhost=true&application=mst-dubbo-pay-consumer&background=false&bind.ip=172.25.147.1&bind.port=20880&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=mst-dubbo-pay-consumer&interface=org.apache.dubbo.metadata.MetadataService&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15420&qos.enable=false&release=3.0.6&revision=3.0.6&side=provider&timestamp=1648092495670&version=1.0.0], dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.813 INFO 15420 --- [ main] o.a.d.r.c.m.ServiceInstanceMetadataUtils : [DUBBO] Start registering instance address to registry., dubbo version: 3.0.6, current host: 172.25.147.1 2022-03-24 11:28:15.818 INFO 15420 --- [ main] o.a.d.c.d.DefaultApplicationDeployer : [DUBBO] Dubbo Application1.1 is ready., dubbo version: 3.0.6, current host: 172.25.147.1

clverhack avatar Mar 24 '22 03:03 clverhack

如果确定是一个纯消费端,并且不想开启 dubbo 端口,可以设置

dubbo:
  application:
     register-consumer: false

chickenlj avatar Mar 28 '22 09:03 chickenlj

如果确定是一个纯消费端,并且不想开启 dubbo 端口,可以设置

dubbo:
  application:
     register-consumer: false

我这里并不起作用,不论register-consumer设置成true还是false,都会启动一个服务监听20880端口

rocketk avatar May 05 '22 09:05 rocketk

+1 好像不起作用。 dubbo 3.0.9 triple

ilaotan avatar Jun 30 '22 10:06 ilaotan

@chickenlj 好像不起作用。 dubbo 3.0.9 triple. 启动了一个提供者 register-consumer: false 后, 消费方还是会消费到。 另外,尝试单独关闭 dubbo.provider.export=false

dubbo:
  provider:
    export: true

这个就不会暴露服务了,但是会有个数组越界的异常。

2022-06-30 18:11:55.625 ERROR 13792 --- [           main] [] [] [] [] o.a.d.c.d.DefaultApplicationDeployer     :  [DUBBO] Dubbo Application[1.1](baseplatform) an exception occurred when handle starting event, dubbo version: 3.0.9, current host: 172.xx.xx.xx
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:659) ~[na:1.8.0_291]
	at java.util.ArrayList.get(ArrayList.java:435) ~[na:1.8.0_291]
	at org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter.export(ConfigurableMetadataServiceExporter.java:71) ~[dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.metadata.ExporterDeployListener.onModuleStarted(ExporterDeployListener.java:70) ~[dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.exportMetadataService(DefaultApplicationDeployer.java:923) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.prepareApplicationInstance(DefaultApplicationDeployer.java:613) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.checkState(DefaultApplicationDeployer.java:824) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.notifyModuleChanged(DefaultApplicationDeployer.java:812) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultModuleDeployer.onModuleStarted(DefaultModuleDeployer.java:255) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:158) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextRefreshedEvent(DubboDeployApplicationListener.java:111) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:100) [dubbo-3.0.9.jar:3.0.9]
	at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) [dubbo-3.0.9.jar:3.0.9]

然后, 这参数和 register-consumer一起设置,就达到效果了,不报错,不暴露服务

ilaotan avatar Jun 30 '22 10:06 ilaotan

能否剥离一个简单的 demo 我们来测试下是哪里的问题

AlbumenJ avatar Jun 30 '22 12:06 AlbumenJ