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

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

  • 相关阅读:
    React Native for Android应用名及图标修改
    如何不使用Navigator空间实现跳转页面?
    ReactNative WebView组件详解
    react-native react-navigation使用
    微信小程序——选择某个区间的数字
    Git分支操作——查看、新建、删除、提交、合并
    Github + Hexo 搭建个人博客
    微信小程序——动态设置swiper的高度
    微信小程序——购物车结算
    解决stackoverflow打开慢的问题
  • 原文地址:https://www.cnblogs.com/asenyang/p/15506548.html
Copyright © 2011-2022 走看看