API

在这里插入图片描述

provider

dubbo:
  application:
    #指定名称
    name: myProvider
  registry:
    address: zookeeper://192.168.217.131:2181?backup=192.168.217.131:2182,192.168.217.131:2183
    timeout: 30000
  #配置服务所使用的协议
  protocol:
    name: dubbo
    port: 20880
  scan:
    base-packages: com.wyt.springbootdubbo_provider.service.impl
package com.wyt.springbootdubbo_provider.service.impl;

import com.wyt.dubbo.service.DemoDubboService;
import org.apache.dubbo.config.annotation.Service;

@Service
public class DemoDubboServiceImpl implements DemoDubboService {

    @Override
    public String showMsg(String str) {
        return "hello dubbo"+str;
    }
}

consumer

dubbo:
  application:
    #指定名称
    name: myConsumer
  registry:
    address: zookeeper://192.168.217.131:2181?backup=192.168.217.131:2182,192.168.217.131:2183
    timeout: 30000
  #配置服务所使用的协议
  protocol:
    name: dubbo
    #consumer中不用配端口,provider中需要



在这里插入图片描述


import com.wyt.springbootdubbo_consumer.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    @Autowired
    private DemoService demoService;
    @RequestMapping("/getMsg")
    public String getMsg(String str){
        return this.demoService.getMsg(str);
    }
}

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐