why dubbo rest protocol need to configure the registry?
when i test dubbo rest protocol, i configure like this according the office website
<dubbo:application name="dubbo-rest"/>
<!--<dubbo:registry address="zookeeper://127.0.0.1:2181"/>-->
<!-- 用rest协议在8080端口暴露服务 -->
<dubbo:protocol name="rest" port="8081" server="tomcat"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.boot.dubbo.CustomerService" ref="customerService"/>
<!-- 和本地bean一样实现服务 -->
<bean id="customerService" class="com.boot.dubbo.CustomerServiceImpl" />
but the error occur like this
java.lang.IllegalStateException: No such any registry to export service in provider 172.19.6.61 use dubbo version 2.6.2, Please add <dubbo:registry address="..." /> to your spring config. If you want unregister, please set <dubbo:service registry="N/A" />
at com.alibaba.dubbo.config.AbstractInterfaceConfig.checkRegistry(AbstractInterfaceConfig.java:120) ~[dubbo-2.6.2.jar:2.6.2]
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:310) ~[dubbo-2.6.2.jar:2.6.2]
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:216) ~[dubbo-2.6.2.jar:2.6.2]
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:123) ~[dubbo-2.6.2.jar:2.6.2]
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:49) ~[dubbo-2.6.2.jar:2.6.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:886) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at com.boot.dubbo.DubboRestApplication.main(DubboRestApplication.java:18) [classes/:na]
it is mean that i need to configure registry,when i configure registry,it works well.but i do not know why?the office website also does not specify if you need the code expample to test,i can provide for you please click the linkDubbo-Rest
I don't think it is a issue for it is the normal logic and registry config is must needed whatever provider/consumer. As the log printing, if you want unregister, please set <dubbo:service registry="N/A" />
but the office doc describe like this
<!-- 用rest协议在8080端口暴露服务 -->
<dubbo:protocol name="rest" port="8080"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="xxx.UserService" ref="userService"/>
<!-- 和本地bean一样实现服务 -->
<bean id="userService" class="xxx.UserServiceImpl" />
Make it easy for us to make mistakes, i think if posibble,the dubbo:registry should be removed. What do you think?
but the office doc describe like this
<!-- 用rest协议在8080端口暴露服务 --> <dubbo:protocol name="rest" port="8080"/> <!-- 声明需要暴露的服务接口 --> <dubbo:service interface="xxx.UserService" ref="userService"/> <!-- 和本地bean一样实现服务 --> <bean id="userService" class="xxx.UserServiceImpl" />Make it easy for us to make mistakes, i think if posibble,the dubbo:registry should be removed. What do you think? Two thinkings here.
-
If the dubbo:registry is removed, the service will not be registered to anywhere. How can a consumer of the service get the addresses? by static DNS? or some other way?
-
If the dubbo:registry is removed, a default registry will be used. What‘s the default? I think it is hard to choose a default behavior for Dubbo because of its open and versatility. A product based Dubbo can extend to implement the default one according the specific scenario.
Which opinion is the better and what is persuasive reasons?
So I think Dubbo can keep the current way without any fixings here.
The rest service is not available as described in the official documentation
<dubbo:registry address="registryprotocol://ip:port"/> is required.
you can refer : https://github.com/a601942905git/boot-dubbo
注意事项
rest协议调用
一定要添加注册中心
@Bean
public RegistryConfig registryConfig() {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
return registryConfig;
}