[准备和初体验](()
[与SpringBoot集成](()
[使用Zookeeper注册中心](()
[管理控制台dubbo-admin](()
创建子工程springbootmulticastprovider,对外提供服务;
创建子工程springbootmulticastconsumer,启动后提供一个web接口,咱们调用这个web接口时,springbootmulticastconsumer会远程调用springbootmulticastprovider提供的服务,如下图:
| 名称 | 链接 | 备注 |
| :-- | :-- | :-- |
| 项目主页 | https://github.com/zq2599/blog_demos | 该项目在GitHub上的主页 |
| git仓库地址(https) | https://github.com/zq2599/blog_demos.git | 该项目源码的仓库地址,https协议 |
| git仓库地址(ssh) | [email protected]:zq2599/blog_demos.git | 该项目源码的仓库地址,ssh协议 |
| 创建顺序 | 文件名 | 作用 |
| — | — | — |
| 1 | pom.xml | 工程的pom文件 |
| 2 | src/main/resources/application.yml | 配置文件 |
| 3 | DemoServiceImpl.java | 提供具体的服务 |
| 4 | SpringBootMulticastProviderApplication.java | 启动类 |
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> dubbopractice com.bolingcavalry 1.0-SNAPSHOT 4.0.0 com.bolingcavalry springbootmulticastprovider 1.0-SNAPSHOT springbootmulticastprovider Demo project for dubbo service provider from Spring Boot, multicast mode org.springframework.boot spring-boot-dependencies ${springboot.version} pom import org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test com.bolingcavalry practiceinterface ${project.version} org.projectlombok lombok org.apache.dubbo dubbo-spring-boot-starter org.springframework.boot spring-boot-maven-plugin ${springboot.version} dubbo: application: #application-name 本模块名字 name: springboot-multicast-provider id: springboot-multicast-provider registry: address: multicast://224.5.6.7:1234 id: registry protocol: name: dubbo port: 20880 package com.bolingcavalry.springbootmulticastprovider; import com.bolingcavalry.dubbopractice.service.DemoService; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.rpc.RpcContext; @Slf4j @Service public class DemoServiceImpl implements DemoService { @Override public String sayHello(String name) { log.info("I’m springboot-multicast-provider, Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackT 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 race(); } return "I’m springboot-multicast-provider, Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress(); } } package com.bolingcavalry.springbootmulticastprovider; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableDubbo public class SpringBootMulticastProviderApplication { public static void main(String[] args) { SpringApplication.run(SpringBootMulticastProviderApplication.class, args); } } | 创建顺序 | 文件名 | 作用 | | — | — | — | | 1 | pom.xml | 工程的pom文件 | | 2 | src/main/resources/application.yml | 配置文件 | | 3 | RemoteInvokeServiceImpl.java | service层,在这里远程调用服务提供方的服务 | | 4 | DemoController.java | web接口类,对外提供web服务 | | 5 | SwaggerConfig.java | swagger配置类,便于通过页面测试接口 | | 6 | SpringBootMulticastConsumerApplication.java | 启动类 | xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> dubbopractice com.bolingcavalry 1.0-SNAPSHOT 4.0.0 com.bolingcavalry springbootmulticastconsumer 1.0-SNAPSHOT springbootmulticastconsumer Demo project for dubbo service consumer from Spring Boot, multicast mode org.springframework.boot spring-boot-dependencies ${springboot.version} pom import org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test io.springfox springfox-swagger2 io.springfox springfox-swagger-ui com.bolingcavalry practiceinterface ${project.version} org.projectlombok lombok
[](()编码(服务消费方)