zoukankan      html  css  js  c++  java
  • dubbo学习笔记二(服务调用)

    项目结构

    代码示例

    由于之前的IEchoService 的一个方法只是在服务端控制台打印,不便在浏览器测试,所以新添加的方法

    api和服务端代码变更

    public interface IEchoService {
        void echo();
    
        String echo(String msg);
    }
    
    @Service
    public class EchoServiceImpl implements IEchoService {
        public void echo() {
            System.out.printf("hello");
        }
    
        public String echo(String msg) {
            return "echo: " + msg;
        }
    }
    
    

    客户端代码

    • [ClientService]
    @Service
    public class ClientService {
        @Reference
        private IEchoService echoService;
    
        public String echo(String msg) {
            return echoService.echo(msg);
        }
    }
    
    • [EchoTestApp]
    @RestController
    @SpringBootApplication
    public class EchoTestApp {
        @Autowired
        private ClientService clientService;
    
        @GetMapping("/hi/{name}")
        public String hello(@PathVariable(name = "name") String name) {
            return clientService.echo(name);
    
        }
    
        public static void main(String[] args) {
            System.getProperties().put("server.port", 7070);
            SpringApplication.run(EchoTestApp.class, args);
        }
    
        @Configuration
        @EnableDubbo(scanBasePackages = "consumer")
        @PropertySource("classpath:/dubbo-consumer.properties")
        static public class ConsumerConfiguration {
    
        }
    }
    
    
    • [dubbo-consumer.properties]
    # dubbo-consumer.properties
    dubbo.application.name=annotation-consumer
    dubbo.registry.address=zookeeper://127.0.0.1:2181
    dubbo.consumer.timeout=3000
    

    浏览器访问

  • 相关阅读:
    EBS R12.2 运行请求出错
    仿ORACLE的TRUNC函数
    EBS职责清单(Responsibility)
    Oracle 11G Client 客户端安装步骤
    UltraIso-写入硬盘映像
    EBS-WIP完工入库
    LeetCode 2 两数相加
    LeetCode 1.两数之和
    装饰器示例
    爬虫day1
  • 原文地址:https://www.cnblogs.com/lanqie/p/10833404.html
Copyright © 2011-2022 走看看