• 使用annnotation方式接入dubbo的操作说明


    dubbo依赖放在common包中,需版本升级为1.0.1-SNAPSHOT
     
    <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> <exclusion> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.6</version> <exclusions> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> <exclusion> <artifactId>log4j</artifactId> <groupId>log4j</groupId> </exclusion> </exclusions> </dependency> 


    ====================服务端====================

    0、项目分包,分离接口与实现类,对外服务接口统一放在facade包里。

    (web,facade,biz(dao+service),integration,test)
    1、项目配置java类添加annotation:
    @ImportResource("classpath:dubbo-server-config.xml")
    
    env.properties文件追加以下配置项
    dubbo.registry.address=zookeeper://127.0.0.1:2181
    dubbo.protocol.name=dubbo
    dubbo.protocol.port=20881
    2、
    dubbo-server-config.xml文件内容:
        <dubbo:application name="${app.name}" />
        <dubbo:registry address="${dubbo.registry.address}" />
        <dubbo:annotation package="...." />
        <dubbo:protocol name="${dubbo.protocol.name}" port="${dubbo.protocol.port}" />
    
    3、服务实现类添加@Service,如下示例:
    @com.alibaba.dubbo.config.annotation.Service(
            version = "1.0.1",
            interfaceClass = EmailSenderFacade.class,
            timeout = 3000,
            delay = -1)
    @Component
    public class EmailSenderService implements EmailSenderFacade {
        //...
    }
    
    ====================消费端====================
    1、项目配置java类添加annotation:
    @ImportResource("classpath:dubbo-consumer-config.xml")
    env.properties文件追加以下配置项
    dubbo.registry.address=zookeeper://127.0.0.1:2181
    
    2、
    dubbo-consumer-config.xml文件内容:
        <dubbo:application name="${app.name}" />
        <dubbo:registry address="${dubbo.registry.address}" />
        <dubbo:annotation package="..." />
    
    3、服务消费配置,如下示例:
    
    @Reference(version="1.0.1")
    private EmailSenderFacade emailSenderFacade;
    
    emailSenderFacade.send...
    
    
    相关软件安装
    e:
    cd E:apache-activemq-5.12.0-binapache-activemq-5.12.0in
    activemq.bat start
    
    d:
    
    
    dubbo服务监控应用:dubbo-admin-2.5.3.war,放在tomcat app目录下,改名为dubbo-admin
    war包中自带有dubbo.properties,修改配置
    dubbo.registry.address=zookeeper://localhost:2181
    dubbo.admin.root.password=root
    
     
     
    启动zookeeper,dubbo-admin:
     
    cd D:zookeeper-3.4.6zookeeper-3.4.6in zkServer.cmd
    cd E:apache-tomcat-6.0.44-x64in
    startup.bat
    
     
    root/root访问http://localhost:9090/dubbo-admin/governance/services 查看发布的服务
  • 相关阅读:
    【python】UI自动化框架搭建.优化
    【fiddler】mock测试
    【postman】对于postman简单的理解
    【pycharm】报错:windows找不到文件chrome
    【python】UI自动化操作属于div标签的滚动条滚动
    【fiddler】fiddler监听local host和127.0.0.1
    【PLSQL】PLSQL过期解决方案(注册机或者修改注册表)
    【奇怪的知识四】:一些常用的下载网站地址
    【奇怪的知识三】:一个可以变色的心形.bat
    python中request获取json数据
  • 原文地址:https://www.cnblogs.com/coding-now/p/14660613.html
Copyright © 2020-2023  润新知