All Products
Search
Document Center

Migrate Dubbo projects to HSF (not recommended)

Last Updated: Feb 02, 2019

EDAS already supports applications and services in the native Dubbo framework. We recommend that beginners do not use this development method.For more information about how to deploy services in the native Dubbo framework, see Connect Dubbo to EDAS.

Configure Dubbo

Dubbo supports two methods for configuring service providers and consumers in EDAS, namely, creating XML configuration files and adding annotations.This topic 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.

Configure service providers with XML files

  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>

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, 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”

Configure service consumers with XML files

  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>

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 registry is ineffective in EDAS, and all Dubbo services are automatically registered to the EDAS configuration center, without the need for manual intervention.
  • A single configuration file allows you to define multiple groups of consumers. 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, and you can directly use the services in EDAS without converting annotations to 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.

Configure multiple registries

Sometimes, the desired services may run in multiple EDAS or ZooKeeper registries. In this case, you need to configure multiple registries in the Dubbo configuration file.For example, if a service is only deployed in Shanghai, you can register the service with two registries so that it can be referenced by applications deployed in Beijing.

Multi-subscription refers to a situation where Dubbo or HSF applications subscribe to services in both the EDAS and ZooKeeper registries while they are consuming a service.

  1. Add a dependency of EDAS SDK version 1.5.1 or later to the current application.

    1. <dependency>
    2. <groupId>com.alibaba.edas</groupId>
    3. <artifactId>edas-sdk</artifactId>
    4. <version>1.5.1</version>
    5. </dependency>
  2. Specify the ZooKeeper registry/subscription center address

    in either of the following two ways:

    • By specifying the environment variable (for HSF and Dubbo applications):

      -Dhsf.registry.address=zookeeper://IP address:Port

    • By adding the following line to the XML file (for HSF applications only):

      <hsf:registry address="zookeeper://IP address:Port" />

    After you specify the ZooKeeper address, Dubbo applications register and subscribe to services in both the EDAS and ZooKeeper registries by default.To achieve the same performance for HSF applications, you must call the invokeType parameter.

  3. Set the call parameters of the multiple registries for HSF applications.

    • To register and subscribe to services in ConfigServer only: invokeType="hsf"
    • To register and subscribe to services in ZooKeeper only: invokeType="dubbo"
    • To register and subscribe to services in both the EDAS and ZooKeeper registries: invokeType="hsf, dubbo"
  4. Select a container of version 3.0 or later when creating an application, and upload and start the application in the container.

Note:

  • Grouping issue: By default, the service group on Dubbo is empty and that in EDAS is HSF.For this reason, you must change the service group on Dubbo.
  • Version issue: By default, the service version on Dubbo is 0.0.0 and that in EDAS is 1.0.0. For this reason, you must change the service version on Dubbo.
  • Subscription successful, but call failed: Service authentication is enabled in EDAS, and therefore you must disable it so that Dubbo can call services successfully. To do this, set the -DneedAuth parameter to false in the JVM parameters and restart EDAS.

Convert JAR to WAR

Currently, EDAS supports web projects in WAR format only. Therefore, if your project was released as a JAR package, you must convert it to WAR first.This topic uses a Maven-based project as an example.

  1. Change packaging from JAR to WAR in the pom.xml file.

    jar-war

  2. Add a web.xml configuration file, if unavailable.

    add-webxml

  3. Configure the web.xml to load the configuration file.

    1. <context-param>
    2. <param-name>contextConfigLocation</param-name>
    3. <param-value>classpath:hsf-provider-beans.xml</param-value>
    4. </context-param>
    5. <listener>
    6. <listener-class>org.springframework.web.context.ContextLoaderListener
    7. </listener-class>
    8. </listener>
    9. <listener>
    10. <listener-class>
    11. org.springframework.web.context.request.RequestContextListener
    12. </listener-class>
    13. </listener>

Dubbo and HSF compatibility

The table below provides a reference for the compatibility between service attributes in Dubbo configuration files and HSF.After inspecting the compatibility of a configuration, you can start application debugging and publishing.

Function or feature Dubbo parameter Compatibility Error message Supported by EDAS
Timeout timeout Yes
Delayed exposure delay Yes
Thread pool dispatcher= “all” threadpool= “fixed” threads= “100” Yes
Echo test Yes
Delay lazy= “true” Enabled by default Yes
Connection
Local calling protocol= “injvm” Yes
Implicit parameter passing Yes
Concurrency control actives=”10” executes=”10” Visible in the EDAS console (Rate Limiting and Downgrade > Rate Limiting Rule > Rate Limiting Granularity) Yes
Connection control accepts=”10” connections=”2” Visible in the EDAS console (Rate Limiting and Downgrade > Rate Limiting Rule > Rate Limiting Granularity) Yes
Service downgrade Visible in the EDAS console (Rate Limiting and Downgrade > Downgrade Rule) Yes
Cluster fault tolerance retries/cluster Retries supported No Partially
Load balancing loadbalance Default: random No Partially
Service groups group * configuration not supported java.lang.IllegalStateException: hsf2, the consumption of multiple groups at the same time not supported Partially
Multi-version version * configuration not supported [HSF-Consumer] cannot find the target address of the service to call Partially
Asynchronous calling async=“true” return=”false” Return parameter invalid No Partially
Check upon startup check Disabled by default No Check upon startup disabled by default
Multi-protocol Only supports Dubbo protocol com.alibaba.dubbo.config.ServiceConfig service
[com.alibaba.demo.api.DemoApi] RMI protocol is configured, not supported by HSF2
Partial support
Routing rules Visible in the EDAS Console, no need to configure Yes
Configuration rules Visible in the EDAS Console, no need to configure Yes
Multi-registry No
Group aggregation group= “aaa,bbb” merger= “true” Yes java.lang.IllegalStateException: hsf2, the consumption of multiple groups at the same time not supported No
Contextual information Yes Caused by: java.lang.UnsupportedOperationException: not support getInvocation method in hsf2 No