美文网首页
dubbo源码8-请求发送响应流程

dubbo源码8-请求发送响应流程

作者: modou1618 | 来源:发表于2019-01-05 22:25 被阅读0次

    一 接口配置

    1.1 接口

    public interface UserService{
    
        /**
         * 依据id查找用户信息
         *
         * @param id 用户id
         * @return 用户,没有则返回null
         */
        User findById(long id);
    }
    

    1.2 consumer端

    <?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-4.0.xsd
                http://code.alibabatech.com/schema/dubbo
                http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    
        <dubbo:application name="${dubbo.app.name}" environment="${dubbo.env}"/>
    
        <dubbo:registry protocol="zookeeper" address="${dubbo.address}" timeout="${zk.connection.timeout}"/>
    
        <dubbo:consumer group="${dubbo.group}" check="false" timeout="${dubbo.timeout}"
                        retries="${dubbo.retries}"/>
    
        <dubbo:reference id="userService" interface="com.greatnew.data.service.UserService"/>
    </beans>
    

    1.3 provider端

    1.3.1 配置

    <?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-4.0.xsd
                http://code.alibabatech.com/schema/dubbo
                http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    
        <dubbo:application name="${dubbo.app.name}" environment="${dubbo.env}"/>
    
        <dubbo:registry protocol="zookeeper" address="${dubbo.address}" timeout="${zk.connection.timeout}"/>
    
        <dubbo:protocol name="dubbo" port="${dubbo.port}"/>
    
        <dubbo:provider group="${dubbo.group}" retries="${dubbo.retries}"/>
    
        <dubbo:service interface="com.greatnew.data.service.UserService" ref="userServiceImpl"/>
    </beans>
    

    1.3.2 接口实现

    public class UserServiceImpl implements UserService {
        @Override
        public User findById(long id) throws RepositoryException {
            return repository.findById(id);
        }
    }
    

    二 调用流程

    image.png

    相关文章

      网友评论

          本文标题:dubbo源码8-请求发送响应流程

          本文链接:https://www.haomeiwen.com/subject/phxjrqtx.html