Spring Cloud之微服务之间相互调用、如何让一个微服务调用另外一个微服务

在使用微服务架构中,可能遇到一些业务情况会涉及服务之间相互调用,下面通过一个简单的demo给大家演示下,演示的是oms服务需要调用ump服务。

代码如下:

1、oms服务提供者

 主要是这个注解:

@EnableFeignClients("com.omsserver.*")

完整代码:

package com.omsserver.service;

//import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @Description: java类作用描述
 * @Author: zhoujh
 * @CreateDate: 2019/5/10$ 11:22 AM$
 * @Version: 1.0
 */

@Service
@FeignClient("ump-service")//服务生产者名称
@RequestMapping("/api/umpinfo")//服务路由
public interface UmpInfoService {


    @RequestMapping("/umpDetails")
    Map<String,Object> umpDetails(String omsId ) ;

}

 

2、ump服务提供者(被调用)

 

完整代码:

package com.umpserver.umpserver.controller;

import com.umpserver.umpserver.service.UmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: java类作用描述
 * @Author: zhoujh
 * @CreateDate: 2019/5/10$ 11:19 AM$
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/umpinfo")//服务路由
public class UmpController {

    @Autowired
    UmpService umpService;

    @RequestMapping("/umpDetails")
    @ResponseBody
    public Map<String,Object> selectUmpInfo(@RequestBody String omsId){
        Map<String,Object> map = new HashMap<>();
        map = umpService.findUmpInfo(omsId);
        return map;
    }
}

 

  • 5
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值