zoukankan      html  css  js  c++  java
  • Dubbo常用功能01--version版本

    version版本:

    version版本号用处是对于同一接口,具有不同的服务实现。

    1、服务端代码:

     1 package com.yas.serviceprovider.impl;
     2 
     3 import com.yas.api.SiteService;
     4 import org.apache.dubbo.config.annotation.Service;
     5 
     6 @Service(version = "default")
     7 public class SiteServiceImpl implements SiteService {
     8     @Override
     9     public String getName(String name) {
    10         return "default:" + name;
    11     }
    12 }
     1 package com.yas.serviceprovider.impl;
     2 
     3 import com.yas.api.SiteService;
     4 import org.apache.dubbo.config.annotation.Service;
     5 
     6 @Service(version = "async")
     7 public class AsyncSiteServiceImpl implements SiteService {
     8     @Override
     9     public String getName(String name) {
    10         return "async:" + name;
    11     }
    12 }

    启动服务端,可以在监控管理后台看到两个服务:

    2、客户端代码:

     1 package com.example.serviceconsumer.controller;
     2 
     3 import com.yas.api.SiteService;
     4 import org.apache.dubbo.config.annotation.Reference;
     5 import org.springframework.web.bind.annotation.RequestMapping;
     6 import org.springframework.web.bind.annotation.RequestParam;
     7 import org.springframework.web.bind.annotation.RestController;
     8 
     9 @RestController
    10 public class SiteController {
    11 
    12     @Reference(version = "default")
    13     SiteService siteService;
    14 
    15     @RequestMapping("/default")
    16     public String getName(@RequestParam("name") String name){
    17         return siteService.getName(name);
    18     }
    19 
    20     @Reference(version = "async")
    21     SiteService asyncSiteService;
    22 
    23     @RequestMapping("/async")
    24     public String getNameByAsync(@RequestParam("name") String name){
    25         return asyncSiteService.getName(name);
    26     }
    27 }

    客户端提供了两个Action,分别调用标注了default的服务和async的服务。

    3、测试:

    使用postman请求:http://localhost:8000/default?name=zhangsan

    得到响应为:default:zhangsan

    使用postman请求:http://localhost:8000/async?name=zhangsan

    得到响应为:async:zhangsan

    实现了从客户端向服务端有指向性的调用。

  • 相关阅读:
    vue 路由跳转返回上一级
    js中Let和Var的区别
    JS实现电话号码校验座机:区号号码、或11位手机号
    VUE 监听 对象属性值变化的三种方式
    vue中computed的用法
    elementUI中input输入框,强制输入数字,并限制输入长度
    C++中__int64用法
    WIN10计算器设计可能出现的坑
    跳转acticity
    asp.net邮件发送
  • 原文地址:https://www.cnblogs.com/asenyang/p/15506548.html
Copyright © 2011-2022 走看看