edit-icon download-icon

Configure Dubbo

Last Updated: Nov 16, 2018

Dubbo supports two methods in configuration of service providers and consumers on EDAS, namely, 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 example codes to your XML configuration files and run them in EDAS if the settings exactly match your environment.

XML configuration for service providers

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  5. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
  6. <dubbo:application name="edas-dubbo-demo-provider" ></dubbo:application>
  7. <bean id="demoProvider" class="com.alibaba.edas.dubbo.demo.provider.DemoProvider" ></bean>
  8. <dubbo:registry address="zookeeper://127.0.0.1:2181" ></dubbo:registry>
  9. <dubbo:protocol name="dubbo" port="20880" threadpool="cached"
  10. threads="100" ></dubbo:protocol>
  11. <dubbo:service delay="-1" interface="com.alibaba.edas.dubbo.demo.api.DemoApi"
  12. ref="demoProvider" version="1.0.0" group="dubbogroup" retries="3" timeout="3000"></dubbo:service>
  13. </beans>

Notes:

  • 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, the current 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

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

NOTES:

  • 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 registry does not take effect on EDAS. All Dubbo services are automatically registered in the EDAS configuration center. You do not have to concern yourself with this.
  • A single configuration file for consumers can define multiple groups. EDAS, however, allows only one group, which is specified by the group attribute.
  • To load services during application startup, set lazy=true for delayed loading.

Add annotations

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

Compatibility:

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

Supported attributes: group, version, and timeout

Use method: When creating a container, select the latest container version, V3.0.

Thank you! We've received your feedback.