当前位置: 首页 > news >正文

Java基础之《dubbo(1)—dubbo基础入门》

一、为什么要使用dubbo

1、dubbo是什么
dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。

2、dubbo有何特点
(1)远程通讯:提供透明化的远程方法调用,提供多协议支持。
(2)集群容错:软负载均衡,失败容错,地址路由,动态配置等集群支持。
(3)自动发现:基于注册中心目录服务,使服务消费方能动态的查找服务提供方,支持平滑减少或增加机器。

3、为什么要使用dubbo
(1)刚起步,技术人员3个,springmvc
一个应用,一个数据库
(2)发展一年,技术人员10个,1个架构师,RPC
将独立的业务抽取出来,形成独立的服务(商品,订单,交易)
多个应用,多个数据库
(3)发展一年半,技术人员80个,服务越来越多,SOA
需要服务自动发现和治理,dubbo、spring cloud、ICE

4、MVC、RPC、SOA的架构如何演进
刚开始直接把系统做出来,推向市场,市场反应好了再改进

5、dubbo与spring cloud、ICE的区别
dubbo2是netty长连接

二、dubbo常用标签

1、application
描述:应用信息,就是当前服务的项目信息配置
特殊说明:无

2、container
描述:服务的运行容器
特殊说明:jetty、log4j、logback、spring

3、provider
描述:服务提供方的一些服务治理、性能调优的一些配置
特殊说明:该标签为当前服务的所有service和protocol标签的缺省值设置

4、service
描述:服务提供者暴露接口配置
特殊说明:无

5、consumer
描述:服务消费方的一些服务治理、性能调优的一些配置
特殊说明:无

6、reference
描述:服务消费者引用接口配置
特殊说明:无

7、registry
描述:注册中心配置
特殊说明:如果有多个不同的注册中心,可以声明多个registry标签,并在service或protocol的registry属性指定使用的注册中心

8、protocol
描述:远程调用协议dubbo、hessian、http、injvm、memcached、redis、rmi、thrift、webservice等
特殊说明:如果需要支持多协议,可以声明多个protocol标签,并在service中通过protocol属性指定使用协议

三、dubbo 3.0入门例子

1、下载官方入门例子
git clone --depth=1 --branch master git@github.com:apache/dubbo-samples.git

2、eclipse打开,只保留1-basic和tools模块,否则项目太多了

    <modules><module>1-basic</module><!--<module>2-advanced</module>--><!--<module>3-extensions</module>--><!--<module>4-governance</module>--><!--<module>10-task</module>--><!--<module>99-integration</module>--><module>tools</module></modules>

3、启动一个简易zookeeper
运行tools/embedded-zookeeper下的EmbeddedZooKeeper.java

/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with* the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package org.apache.dubbo.samples;import java.io.File;
import java.util.Properties;
import java.util.UUID;import org.apache.zookeeper.server.ServerConfig;
import org.apache.zookeeper.server.ZooKeeperServerMain;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;public class EmbeddedZooKeeper {public static void main(String[] args) throws Exception {int port = 2181;if (args.length == 1) {port = Integer.parseInt(args[0]);}Properties properties = new Properties();File file = new File(System.getProperty("java.io.tmpdir")+ File.separator + UUID.randomUUID());file.deleteOnExit();properties.setProperty("dataDir", file.getAbsolutePath());properties.setProperty("clientPort", String.valueOf(port));QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();quorumPeerConfig.parseProperties(properties);ZooKeeperServerMain zkServer = new ZooKeeperServerMain();ServerConfig configuration = new ServerConfig();configuration.readFrom(quorumPeerConfig);try {zkServer.runFromConfig(configuration);} catch (Exception e) {e.printStackTrace();System.exit(1);}}
}

4、启动服务提供者
运行1-basic/dubbo-samples-api下的org.apache.dubbo.samples.provider包内的Application.java

/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with* the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.apache.dubbo.samples.provider;import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.samples.api.GreetingsService;public class Application {private static final String ZOOKEEPER_HOST = System.getProperty("zookeeper.address", "127.0.0.1");private static final String ZOOKEEPER_PORT = System.getProperty("zookeeper.port", "2181");private static final String ZOOKEEPER_ADDRESS = "zookeeper://" + ZOOKEEPER_HOST + ":" + ZOOKEEPER_PORT;public static void main(String[] args) {ServiceConfig<GreetingsService> service = new ServiceConfig<>();service.setInterface(GreetingsService.class);service.setRef(new GreetingsServiceImpl());DubboBootstrap.getInstance().application("first-dubbo-provider").registry(new RegistryConfig(ZOOKEEPER_ADDRESS)).protocol(new ProtocolConfig("dubbo", -1)).service(service).start().await();}
}

5、启动服务消费者
运行1-basic/dubbo-samples-api下的org.apache.dubbo.samples.client包内的AlwaysApplication.java

/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with* the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.apache.dubbo.samples.client;import java.io.IOException;
import java.util.Date;import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.samples.api.GreetingsService;public class AlwaysApplication {private static final String ZOOKEEPER_HOST = System.getProperty("zookeeper.address", "127.0.0.1");private static final String ZOOKEEPER_PORT = System.getProperty("zookeeper.port", "2181");private static final String ZOOKEEPER_ADDRESS = "zookeeper://" + ZOOKEEPER_HOST + ":" + ZOOKEEPER_PORT;public static void main(String[] args) throws IOException {ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();reference.setInterface(GreetingsService.class);DubboBootstrap.getInstance().application("first-dubbo-consumer").registry(new RegistryConfig(ZOOKEEPER_ADDRESS)).reference(reference).start();GreetingsService service = reference.get();while (true) {try {String message = service.sayHi("dubbo");System.out.println(new Date() + " Receive result ======> " + message);Thread.sleep(1000);} catch (Throwable t) {t.printStackTrace();}}}}

6、打印日志

Wed Mar 08 17:05:04 CST 2023 Receive result ======> hi, dubbo
Wed Mar 08 17:05:05 CST 2023 Receive result ======> hi, dubbo
Wed Mar 08 17:05:06 CST 2023 Receive result ======> hi, dubbo
Wed Mar 08 17:05:07 CST 2023 Receive result ======> hi, dubbo
Wed Mar 08 17:05:08 CST 2023 Receive result ======> hi, dubbo
......

相关文章:

Java基础之《dubbo(1)—dubbo基础入门》

一、为什么要使用dubbo 1、dubbo是什么 dubbo是一个分布式服务框架&#xff0c;致力于提供高性能和透明化的RPC远程服务调用方案&#xff0c;以及SOA服务治理方案。 2、dubbo有何特点 &#xff08;1&#xff09;远程通讯&#xff1a;提供透明化的远程方法调用&#xff0c;提供…...

HTML注入的一种攻击思路(超链接替换为点击验证,现在常见)

目录 背景 利用方法 举一反三 场景1:截获 TOKEN 场景2:截获后台信息 总结...

Redis-6集群

文章目录前言Redis集群原理搭建Redis集群集群拓展后记前言 前两期介绍和搭建了Redis的主从复制架构和哨兵模式&#xff0c;虽然哨兵模式能够实现自动故障转移主备切换&#xff0c;一定程度上提高了系统的容错性 但这两种架构模式都不能解决单节点的并发压力和物理上线的问题&…...

Spring Cloud学习笔记:基础知识

这是本人学习的总结&#xff0c;主要学习资料如下 马士兵教育 目录1、Spring Cloud 简介2、Eureka3、建立Spring Cloud项目3.1、启动Server3.1.1、dependency3.1.2、配置文件3.1.3、Server端启动代码3.2、启动Client3.2.1、dependency3.2.2、配置文件3.3.3、Client端启动代码3…...

农产品销售系统/商城,可运行

文章目录项目介绍一、项目功能介绍1、用户模块主要功能包括&#xff1a;2、商家模块主要功能包括&#xff1a;3、管理员模块主要功能包括&#xff1a;二、部分页面展示1、用户模块部分功能页面展示2、商家模块部分功能页面展示3、管理员模块部分功能页面展示三、部分源码四、底…...

【Java开发】JUC进阶 05:函数式接口、ForkJoin

1 四大函数式接口函数式接口&#xff1a;只有一个抽象方法的接口&#xff0c;只要是函数式接口&#xff0c;就可以用lambda表达式简化例如Runnable&#xff1a;FunctionalInterface public interface Runnable {public abstract void run(); }框架底层大量应用函数式接口&#…...

Nginx支持quic协议

第一种方式&#xff1a;Nginx官方nginx-quic搭建 通过部署Nginx官方的QUIC分支来实现的浏览器和nginx-quic服务器粗略的HTTP3通信。 1、下载BoringSSL BoringSSL 是由谷歌开发,从 OpenSSL 中分离的一个分支。BoringSSL 是 Chrome/Chromium、Android&#xff08;但它不是 NDK 的…...

笔记 - Java 内存结构与模型

-- Java里内存结构与内存模型是两种概念 一、Java内存结构&#xff1a; HeapMemory - 堆内存Java Stacks - 栈内存 &#xff08;运行时&#xff09;Method Area - 方法区Native Method Stack - 本地方法栈 真实和系统打交道的地方Jit Compiler - 将java运行指令编译成机器指令G…...

C#基础教程12 数组

文章目录 C# 数组(Array)C# 中的数组声明数组初始化数组赋值给数组访问数组元素C# 数组细节C# 数组(Array) 数组是一个存储相同类型元素的固定大小的顺序集合。数组是用来存储数据的集合,通常认为数组是一个同一类型变量的集合。 声明数组变量并不是声明 number0、number1…...

Android中级——屏幕和绘图

屏幕和绘图屏幕系统屏幕密度独立像素密度dp单位转换XML绘图&#xff08;需放在Drawable&#xff09;BitmapShapeLayerSelector绘图技巧CanvasLayerPorterDuffXfermodeShaderPathEffectSurfaceView屏幕 屏幕大小&#xff1a;指屏幕对角线长度&#xff0c;单位为寸分辨率&#x…...

Linux - 第6节 - 动态库和静态库

1.静态库与动态库概念 静态库&#xff08;.a&#xff09;&#xff1a;程序在编译链接的时候把库的代码拷贝到可执行文件中。程序运行的时候将不再需要静态库。动态库&#xff08;.so&#xff09;&#xff1a;程序在运行的时候才去链接动态库的代码&#xff0c;多个程序共享使用…...

【Java学习笔记】12.Character 类及String 类

前言 本章介绍Java的Character 类和String 类。 Java Character 类 Character 类用于对单个字符进行操作。 Character 类在对象中包装一个基本类型 char 的值 实例 char ch a;// Unicode 字符表示形式 char uniChar \u039A; // 字符数组 char[] charArray { a, b, c, d…...

【C++修炼之路】26.C++11(语法糖)

每一个不曾起舞的日子都是对生命的辜负 C11C11(语法糖)本节目标一.C11简介二.统一的列表初始化2.1 {}初始化2.2 std::initializer_list三.声明3.1 auto3.2 decltype3.3 nullptr四.总结C11(语法糖) 本节目标 C11简介 列表初始化 变量类型推导 一.C11简介 在2003年C标准委员…...

KD610精密油介损体积电阻率测试仪

一、概述 KD610精密油介损体积电阻率测试仪是用于绝缘油等液体绝缘介质的介质损耗角及体积电阻率的高精密仪器。 二、产品特点 1&#xff0e;仪器内部采用数字技术&#xff0c;具备多种模式测式。 2&#xff0e;智能自动化测量。 3&#xff0e;配备了大屏幕&#xff08;2401…...

快速了解原码、反码、补码和位运算

我们知道计算机使用的是二进制&#xff0c;我们⽤⼀个字节&#xff0c;也就是8个bit 来表示⼆进制数。 原码 十进制 原码20000 0010-21000 0010 原码其实是最容易理解的&#xff0c;只不过需要利⽤⼆进制中的第⼀位来表示符号位&#xff0c;0表示正数&#xff0c;1表示…...

算法的复杂度介绍

算法的复杂度介绍 算法&#xff08;Algorithm&#xff09;是指用来操作数据、解决程序问题的一组方法。对于同一个问题&#xff0c;使用不同的算法&#xff0c;也许最终得到的结果是一样的&#xff0c;但在过程中消耗的资源和时间却会有很大的区别。 为什么要进行算法分析&…...

教你如何搭建店铺—收支管理系统,demo可分享

1、简介1.1、案例简介本文将介绍&#xff0c;如何搭建店铺-收支管理。1.2、应用场景以店铺收支管理为核心&#xff0c;维度数据分析&#xff0c;智能指导门店经营&#xff0c;账目清晰一目了然&#xff0c;店铺经营更高效。2、设置方法2.1、表单搭建1&#xff09;新建表单【客户…...

java性能分析-堆内存最佳实践-堆分析

堆内存最佳实践 优化垃圾回收器标志参数很重要但是采用更好的编程实践获得更大的性能提升 1.谨慎的创建对象并尽快的丢弃&#xff0c;是更好的内存是提高gc更好的方法 2.频繁创建某种类型的对象会导致整体的性能变差 对象复用设计 线程局部变量 每个线程中创建一个局部变量…...

3月8号作业

题目&#xff1a;题目一&#xff1a;vmlinux可执行文件如何产生题目二&#xff1a;整理内核编译流程&#xff1a;uImage&#xff0c;zImage,Image,vmlinux之间的关系答案一&#xff1a;在内核源码目录下vi Makefile&#xff0c;搜索vmlinux目标&#xff0c;vmlinux: scripts/li…...

Flink相关介绍

简介 Flink的定位是&#xff1a;Apache Flink是一个框架和分布式处理引擎&#xff0c;如图所示&#xff0c;用于对无界和有界数据流进行有状态计算。Flink被设计在所有常见的集群环境运行&#xff0c;以内存执行速度和任意规模来执行计算。 Flink 框架处理流程应用场景 1、电…...

像素幻梦·创意工坊实操手册:实时HUD状态栏信息读取与调试技巧

像素幻梦创意工坊实操手册&#xff1a;实时HUD状态栏信息读取与调试技巧 1. 认识像素幻梦的HUD状态栏 像素幻梦创意工坊的HUD&#xff08;Head-Up Display&#xff09;状态栏位于界面顶部&#xff0c;采用16-bit像素风格设计&#xff0c;为创作者提供实时系统状态反馈。这个看…...

别再让运动模糊毁了你的检测!一文搞懂工业相机飞拍里的CMOS传感器与快门速度怎么配

工业相机飞拍实战&#xff1a;CMOS传感器与快门速度的黄金搭配法则 在一条每分钟处理300个瓶盖的高速灌装线上&#xff0c;质检员小王发现相机拍摄的字符总是出现拖影——这已经是本周第三次因图像模糊导致误检停线了。类似场景每天都在全球数以万计的自动化产线上演&#xff0…...

Unity开发HoloLens应用:从打包到安装的完整避坑指南(2024最新版)

Unity开发HoloLens应用&#xff1a;从打包到安装的完整避坑指南&#xff08;2024最新版&#xff09; 如果你正在尝试将Unity项目部署到HoloLens设备上&#xff0c;可能会遇到各种意想不到的问题。作为一位经历过无数次打包、部署、调试循环的开发者&#xff0c;我想分享一些实战…...

GME-Qwen2-VL-2B-Instruct效果扩展:多风格艺术画作的理解与情感分析展示

GME-Qwen2-VL-2B-Instruct效果扩展&#xff1a;多风格艺术画作的理解与情感分析展示 最近在玩一个挺有意思的视觉语言模型&#xff0c;叫GME-Qwen2-VL-2B-Instruct。它个头不大&#xff0c;但能力挺让人意外。我突发奇想&#xff0c;把它当成了一个“数字艺术评论员”&#xf…...

Qwen3-ASR-0.6B在新闻行业的应用:采访录音快速转写

Qwen3-ASR-0.6B在新闻行业的应用&#xff1a;采访录音快速转写 1. 引言 新闻记者每天都要面对大量的采访录音&#xff0c;传统的手工转写方式耗时耗力。一段30分钟的采访录音&#xff0c;熟练的转录员可能需要2-3小时才能完成转写&#xff0c;而且还要面对口音、专业术语、背…...

别再写重复代码了!手把手教你用StringRedisTemplate搞定Shop-Type缓存(附完整代码)

告别重复劳动&#xff1a;基于StringRedisTemplate的Shop-Type缓存通用方案设计 在电商系统开发中&#xff0c;店铺分类(Shop-Type)这类基础数据的缓存处理几乎每个项目都会遇到。许多开发者习惯在每个Service中重复编写相似的缓存逻辑——序列化、反序列化、缓存判空、数据库回…...

nli-distilroberta-base轻量化效果实测:在嵌入式设备上的推理性能与精度

nli-distilroberta-base轻量化效果实测&#xff1a;在嵌入式设备上的推理性能与精度 1. 开篇&#xff1a;当大模型遇上小设备 在树莓派上跑BERT&#xff1f;半年前这还是个笑话。但当我第一次在Jetson Nano上成功运行量化后的nli-distilroberta-base模型时&#xff0c;这个4核…...

终极指南:Windows免费倒计时神器Hourglass,5分钟从新手到高手

终极指南&#xff1a;Windows免费倒计时神器Hourglass&#xff0c;5分钟从新手到高手 【免费下载链接】hourglass The simple countdown timer for Windows. 项目地址: https://gitcode.com/gh_mirrors/ho/hourglass 还在为Windows系统找不到好用的倒计时工具而烦恼吗&a…...

Flash闪存技术

1 Mask ROM Cartridges: ROM卡带, Character ROM (CHR ROM) and the Program ROM (PRG ROM). Both of them are Mask ROM. SRAM or EEPROM: game status saving. Moto 6502: 6502 -> ST7 -> STM82 HDD Low-level formatting 低级格式化历史&#xff1a;HDD一个完整扇区包…...

Piping Server开发者指南:如何基于流传输构建自己的应用

Piping Server开发者指南&#xff1a;如何基于流传输构建自己的应用 【免费下载链接】piping-server Infinitely transfer between every device over pure HTTP with pipes or browsers 项目地址: https://gitcode.com/gh_mirrors/pi/piping-server Piping Server是一个…...