Springboot集成dubbo使用nacos作为服务注册订阅

  1. 在nacos已经存在的情况下,springboot配置dubbo集成,pom引入依赖包
<dubbo-spring-boot-starter.version>0.2.1.RELEASE</dubbo-spring-boot-starter.version>
        <nacos-discovery-spring-boot-starter.version>0.2.1</nacos-discovery-spring-boot-starter.version>
        <dubbo.version>2.6.5</dubbo.version>
        <dubbo-registry-nacos.version>0.0.1</dubbo-registry-nacos.version>
        <dubbo-spring-context-support.version>1.0.2</dubbo-spring-context-support.version>
<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo-registry-nacos</artifactId>
            <version>${dubbo-registry-nacos.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.spring</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${dubbo-spring-context-support.version}</version>
        </dependency>
        <!-- dubbo + nacos end -->
        <!-- dubbo + spring-boot + nacos start -->
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>${dubbo-spring-boot-starter.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.alibaba</groupId>
                    <artifactId>dubbo</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>nacos-discovery-spring-boot-starter</artifactId>
            <version>${nacos-discovery-spring-boot-starter.version}</version>
        </dependency>

工程application.yml配置dubbo,nacos相关信息
dubbo:
application:
name: 应用名
version: 版本说明
registry:
address: nacos://ip:8848
scan:
base-packages: xxxx.service
protocol:
name: dubbo
port: 20880
定义注册的接口

@Service
public interface IFileService {
	public Map<String, String> storageFile(String businessType, String fileName,
			String corpCode, byte[] fileData, String systemType)
			throws Exception;
			}

调用接口的类注入上述接口
import com.alibaba.dubbo.config.annotation.Reference;
@Reference
private IFileService fileService;

  1. springboot使用hessian实现rpc,无须服务注册和服务发现,使用http方式发布接口和调用接口
    引入依赖
<dependency>
   <groupId>com.caucho</groupId>
    <artifactId>hessian</artifactId>
    <version>4.0.51</version>
</dependency>

服务提供方

@Bean(name = "/rpc/appRedisService")
	public HessianServiceExporter appRedisService() {
		HessianServiceExporter exporter = new HessianServiceExporter();
		exporter.setService(appRedisServiceImpl);
		exporter.setServiceInterface(IRedisAppService.class);
		return exporter;
	}

服务调用方

@Bean
  public HessianProxyFactoryBean redisRpcClient() {
    HessianProxyFactoryBean hessianProxyFactory = new HessianProxyFactoryBean();
    hessianProxyFactory.setServiceUrl("http://IP:port/rpc/redisService");
    hessianProxyFactory.setServiceInterface(IRedisService.class);
    return hessianProxyFactory;
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值