Dubbo应用
2021-09-04 本文已影响0人
ythmilk
环境搭建
- zookeeper 下载安装(环境变量配置)
项目搭建
项目模块
Dubbo-demo-provider
Dubbo-demo-consumer
Dubbo-demo-sdk
Maven 依赖
<properties>
<zookeeper.version>2.12.0</zookeeper.version>
</properties>
<!--zookeeper-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.7</version>
</dependency>
<!--dubbo引入-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${zookeeper.version}</version>
</dependency>
dubbo-admin(Dubbo控制台)
GitHub地址:https://github.com/apache/dubbo-admin
下载代码,执行 mvn clean package -Dmaven.test.skip=true
元数据出不来
解决办法:https://blog.csdn.net/wangxq0224/article/details/99304253
- 添加zk节点
package com.yth.dubbo.provider.service.impl; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; public class Test { public static void main(String[] args) { try { CuratorFramework zkClient = CuratorFrameworkFactory.builder(). connectString("127.0.0.1:2181"). retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); zkClient.start(); if (zkClient.checkExists().forPath("/dubbo/config/dubbo/dubbo.properties") == null) { zkClient.create().creatingParentsIfNeeded().forPath("/dubbo/config/dubbo/dubbo.properties"); } zkClient.setData().forPath("/dubbo/config/dubbo/dubbo.properties", ("dubbo.registry.address=zookeeper://127.0.0.1:2181\n" + "dubbo.metadata-report.address=zookeeper://127.0.0.1:2181").getBytes()); } catch (Exception e) { e.printStackTrace(); } } }
- application.properties配置
dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
- application.properties配置
dubbo-monitor(监控中心)
用来统计服务的调⽤次数和调⽤时间的监控中⼼。
代码路径