Java教程

微服务与 dubbo

本文主要是介绍微服务与 dubbo,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

官方网址

https://dubbo.apache.org/zh

Apache Dubbo 提供了六大核心能力:

1,面向接口代理的高性能RPC调用,
2,智能容错和负载均衡,
3,服务自动注册和发现,
4,高度可扩展能力,
5,运行期流量调度,
6,可视化的服务治理与运维。

生产者示例:

安装jdk

[root@mq-node1 ~]# apt install openjdk-8-jdk -y

创建目录

[root@mq-node1 ~]# mkdir /apps -p

解压

[root@mq-node1 ~]# tar xf dubbo-demo-provider-2.1.5-assembly.tar.gz -C /apps/

做个软链接

[root@mq-node1 ~]# ln -s /apps/dubbo-demo-provider-2.1.5 /apps/dubbo-demo-provider

修改配置

[root@mq-node1 ~]# vim /apps/dubbo-demo-provider/conf/dubbo.properties

#dubbo.registry.address=multicast://224.5.6.7:1234
# zookeeper集群
dubbo.registry.address=zookeeper://172.31.2.41:2181 | zookeeper://172.31.2.42:2181 | zookeeper://172.31.2.43:2181

启动

[root@mq-node1 ~]# /apps/dubbo-demo-provider/bin/start.sh

Starting the demo-provider ....OK!
PID: 9304
STDOUT: logs/stdout.log

查看端口20880

[root@mq-node1 ~]# ss -tanl
LISTEN               0                     50                                          0.0.0.0:20880                                    0.0.0.0:*

消费者示例:

部署 consumer:

安装jdk

[root@mq-node2 ~]# apt install openjdk-8-jdk -y

创建目录

[root@mq-node2 ~]# mkdir -p /apps

解压

[root@mq-node2 ~]# tar xf dubbo-demo-consumer-2.1.5-assembly.tar.gz -C /apps/

修改配置

[root@mq-node2 ~]# vim /apps/dubbo-demo-consumer-2.1.5/conf/dubbo.properties

#dubbo.registry.address=multicast://224.5.6.7:1234
# zookeeper集群
dubbo.registry.address=zookeeper://172.31.2.41:2181 | zookeeper://172.31.2.42:2181 | zookeeper://172.31.2.43:2181

启动

[root@mq-node2 ~]# /apps/dubbo-demo-consumer-2.1.5/bin/start.sh

Starting the demo-consumer ....OK!
PID: 8705
STDOUT: logs/stdout.log

验证 consumer 日志:

[root@mq-node2 ~]# tail -f /apps/dubbo-demo-consumer-2.1.5/logs/stdout.log
[07:34:46] Hello world28, response form provider: 172.31.2.44:20880
[07:34:48] Hello world29, response form provider: 172.31.2.44:20880
[07:34:50] Hello world30, response form provider: 172.31.2.44:20880
[07:34:52] Hello world31, response form provider: 172.31.2.44:20880
[07:34:54] Hello world32, response form provider: 172.31.2.44:20880

验证 provider 日志:

consumer会打开随机端口调用,默认每隔2s一次

[root@mq-node1 ~]# tail -f /apps/dubbo-demo-provider/logs/stdout.log
[07:35:36] Hello world53, request from consumer: /172.31.2.45:53836
[07:35:38] Hello world54, request from consumer: /172.31.2.45:53836
[07:35:40] Hello world55, request from consumer: /172.31.2.45:53836
[07:35:42] Hello world56, request from consumer: /172.31.2.45:53836

dubbo admin

解压tomcat

[root@mq1 ~]# tar xf apache-tomcat-8.5.54.tar.gz -C /apps

解压

[root@mq1 webapps]# unzip dubboadmin.war

修改配置

[root@mq1 webapps]# vim dubboadmin/WEB-INF/dubbo.properties

dubbo.registry.address=zookeeper://172.31.2.42:2181
dubbo.admin.root.password=root

因为kafka占用8080,修改Tomcat默认端口

[root@mq1 webapps]# vim /apps/apache-tomcat-8.5.54/conf/server.xml

<Connector port="8090" protocol="HTTP/1.1"

启动Tomcat

[root@mq1 webapps]# /apps/apache-tomcat-8.5.54/bin/catalina.sh start

查看端口


浏览器登录:http:ip:8090/dubboadmin

账户密码都是:root

这篇关于微服务与 dubbo的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!