dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

why dubbo rest protocol need to configure the registry?

Open a601942905git opened this issue 8 years ago • 6 comments

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

a601942905git avatar Oct 30 '18 02:10 a601942905git

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" />

Jeff-Lv avatar Oct 30 '18 06:10 Jeff-Lv

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?

a601942905git avatar Oct 30 '18 06:10 a601942905git

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.

  1. 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?

  2. 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.

Jeff-Lv avatar Oct 31 '18 06:10 Jeff-Lv

The rest service is not available as described in the official documentation

a601942905git avatar Oct 31 '18 11:10 a601942905git

<dubbo:registry address="registryprotocol://ip:port"/> is required.

zonghaishang avatar Oct 31 '18 15:10 zonghaishang

you can refer : https://github.com/a601942905git/boot-dubbo

注意事项
rest协议调用
一定要添加注册中心
@Bean
public RegistryConfig registryConfig() {
  RegistryConfig registryConfig = new RegistryConfig();
  registryConfig.setAddress("N/A");
  return registryConfig;
}

zonghaishang avatar Oct 31 '18 15:10 zonghaishang