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

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

  • 相关阅读:
    CVE-2019-16097:Harbor任意管理员注册漏洞复现
    wfi破解
    Phpstudy隐藏后门
    远程桌面--------ms12-020 漏洞复现 (死亡蓝屏)
    心脏滴血漏洞复现(CVE-2014-0160)
    疑难杂症----克隆虚拟机无法上网
    疑难杂症----Windows10
    mono修改代码模板
    mono for android 各版本下载地址(目前没多大参考价值了,老文章了)
    单独安装VS2012装mono for android
  • 原文地址:https://www.cnblogs.com/asenyang/p/15506548.html
Copyright © 2011-2022 走看看