edit-icon download-icon

Configure Dubbo

Last Updated: Jan 16, 2018

Dubbo supports two methods to configure service providers and consumers in EDAS: creating XML configuration files and adding annotations. This document describes the two configuration methods with examples.

Create XML configuration files

You can directly copy the following sample codes and run them in EDAS if the settings are correctly configured.

XML configuration for service providers

```xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <dubbo:application name="edas-dubbo-demo-provider" ></dubbo:application>
    <bean id="demoProvider" class="com.alibaba.edas.dubbo.demo.provider.DemoProvider" ></bean>
    <dubbo:registry address="zookeeper://127.0.0.1:2181" ></dubbo:registry>

    <dubbo:protocol name="dubbo" port="20880" threadpool="cached"
    threads="100" ></dubbo:protocol>

    <dubbo:service delay="-1" interface="com.alibaba.edas.dubbo.demo.api.DemoApi"
        ref="demoProvider" version="1.0.0" group="dubbogroup" retries="3" timeout="3000"></dubbo:service>

    </beans>
```

Note:

  • These parameters are optional: threadpool, threads, delay, version, retries, and timeout. Others are required. The positions of the parameters can be changed as needed.
  • Dubbo's RPC protocol supports various methods, such as RMI and Hessian. However, currently EDAS only supports the Dubbo protocol, for example, <dubbo:protocol name="dubbo" port=“20880”>; otherwise, an error like the following is reported: "com.alibaba.dubbo.config.ServiceConfig service [xx.xx.xxx] contain xx protocol, HSF not supported".

XML configuration for service consumers

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="edas-dubbo-consumer" />
<dubbo:registry address="zookeeper://127.0.0.1:2181" />
<dubbo:reference id="demoProviderApi"
interface="com.alibaba.edas.dubbo.demo.api.DemoApi" version="1.0.0" group="dubbogroup" lazy="true" loadbalance="random">
<!-- Define a method that does not wait for a return value -->
<dubbo:method name="sayMsg" async="true" return="false" />
</dubbo:reference>
<bean id="demoConsumer" class="com.alibaba.edas.dubbo.demo.consumer.DemoConsumer"
init-method="reviceMsg">
<property name="demoApi" ref="demoProviderApi"></property>
</bean>
</beans>

Note:

  • These parameters are optional: version, group, lazy, loadbalance, async, and return. Others are required. The positions of the parameters can be changed as needed.
  • The registration center does not take effect in EDAS. All Dubbo services are automatically registered in the EDAS configuration center. You do not have to concern yourself with this.
  • In the configuration file of Dubbo, the consumer can define multiple service groups. EDAS, however, allows only one service group, which is specified by the group attribute.
  • To load services during your application startup, set lazy=true for delayed loading.

Add annotations

EDAS Container V3.0 and later versions support Dubbo native annotations. You can directly use the services in EDAS without converting annotations into XML files.

Compatibility:

  • Service publishing annotation: @Service
  • Service subscription annotation: @Reference

Supported attributes: group, version, and timeout

Usage: When creating a container, select container version V3.0 or later.

Thank you! We've received your feedback.