SOFARPC(笔记)
文章目录
- 一、快速开始
- 1.1 SOFARPC
- 1.2 基于SOFABoot
- 二、注册中心
- 三、通讯协议
- 2.1 Bolt
- 基本发布
- 调用方式
- 超时控制
- 协议泛化调用
- 序列化协议
- 自定义线程池
- 2.2 RESTful
- 基本使用
- 2.3 其他协议
- 四、架构
- 附录
官方样例下载地址-sofa-boot-guides
可查看 SOFARPC 方式快速入门
一、快速开始
1.1 SOFARPC
导入如下依赖
<dependency><groupId>com.alipay.sofa</groupId><artifactId>sofa-rpc-all</artifactId><version>最新版本</version>
</dependency>
版本查看
创建一个接口
public interface HelloService {String sayHello(String string);
}
实现它
public class HelloServiceImpl implements HelloService {@Overridepublic String sayHello(String string) {System.out.println("Server receive: " + string);return "hello " + string + " !";}
}
服务器代码
import com.alipay.sofa.rpc.config.ProviderConfig;
import com.alipay.sofa.rpc.config.ServerConfig;public class QuickStartServer {public static void main(String[] args) {ServerConfig serverConfig = new ServerConfig().setProtocol("bolt") // 设置一个协议,默认bolt.setPort(12200) // 设置一个端口,默认12200.setDaemon(false); // 非守护线程ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()) // 指定接口.setRef(new HelloServiceImpl()) // 指定实现.setServer(serverConfig); // 指定服务端providerConfig.export(); // 发布服务}
}
客户端代码
import com.alipay.sofa.rpc.config.ConsumerConfig;public class QuickStartClient {public static void main(String[] args) {ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setInterfaceId(HelloService.class.getName()) // 指定接口.setProtocol("bolt") // 指定协议.setDirectUrl("bolt://127.0.0.1:12200"); // 指定直连地址// 生成代理类HelloService helloService = consumerConfig.refer();while (true) {System.out.println(helloService.sayHello("world"));try {Thread.sleep(2000);} catch (Exception e) {}}}
}
1.2 基于SOFABoot
引入如下依赖
<parent><groupId>com.alipay.sofa</groupId><artifactId>sofaboot-dependencies</artifactId><version>3.2.0</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.alipay.sofa</groupId><artifactId>rpc-sofa-boot-starter</artifactId></dependency></dependencies>
以及基本的SpringBoot配置
spring.application.name=rpcApp
logging.path=./logs
server.port=8080
服务接口
package com.SOFABootRPCTest.service;public interface AnnotationService {String sayAnnotation(String string);
}
服务实现接口
在前文中,我们用@Configuration、@Bean+@SofaService来完成的发布与引用,我们这里就直接用@Service+@SofaService的方式完成
package com.SOFABootRPCTest.serviceImpl;import com.SOFABootRPCTest.service.AnnotationService;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import org.springframework.stereotype.Service;@SofaService(interfaceType = AnnotationService.class, uniqueId = "annotationServiceImpl", bindings = { @SofaServiceBinding(bindingType = "bolt")})
@Service
public class AnnotationServiceImpl implements AnnotationService {@Overridepublic String sayAnnotation(String string) {return string;}
}
bolt这里是协议,我们在前文中这个地方是jvm。不同协议用法不同。可以看到,默认是jvm协议。
上面代表我们的接口就正式发布了。可以通过互联网进行访问。
我们现在要调用我们发布的接口,基本和jvm一样。jvmFirst默认为True,也就是优先使用jvm协议。
package com.client;import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.service.AnnotationService;
import org.springframework.stereotype.Component;@Component
public class AnnotationClientImpl {@SofaReference(interfaceType = AnnotationService.class, jvmFirst = false,uniqueId = "annotationServiceImpl",binding = @SofaReferenceBinding(bindingType = "bolt"))private AnnotationService annotationService;public String sayClientAnnotation(String str) {return annotationService.sayAnnotation(str);}
}
使用起来很像Fegin直接调用方法即可。
文档给的代码如下。也可以用 阿里官方给的 SOFARPC快速入门里面的代码。
将下列main中代码放入当前MainApplication中,即可。
package com.SOFABootRPCTest.client;import com.SOFABootRPCTest.Contoller.AnnotationClientImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;public class AnotationClientApplication {public static void main(String[] args) {// 临时切换地址,避免端口重复System.setProperty("server.port", "8081");SpringApplication springApplication = new SpringApplication(AnotationClientApplication.class);ApplicationContext applicationContext = springApplication.run(args);AnnotationClientImpl annotationService = applicationContext.getBean(AnnotationClientImpl.class);String result = annotationService.sayClientAnnotation("annotation");System.out.println("invoke result:" + result);}
}
二、注册中心
笔者使用Nacos作为注册中心,其他注册中心可参考注册中心
使用时注意版本要求
图方便可以用本地文件作为注册中心
三、通讯协议
我们此处仅尝试注解方式的发布引用。
可以自行参考协议基本使用
可以创建如下结构项目
2.1 Bolt
基本发布
api中创建
package com.serviceApi;public interface SampleService {String HelloWorld();
}
producer中创建
package com.producer.serviceImpl;import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import com.serviceApi.SampleService;
import org.springframework.stereotype.Service;@Service
@SofaService(uniqueId = "sampleService",bindings = {@SofaServiceBinding(bindingType = "bolt")})
public class SampleServiceImpl implements SampleService {@Overridepublic String HelloWorld() {System.out.println("==========================\nhello world!\n==========================\n");return "hello world";}
}
consumer中使用
package com.consumer;import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.serviceApi.SampleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsumerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class test {@SofaReference(uniqueId = "sampleService",binding = @SofaReferenceBinding(bindingType = "bolt"))private SampleService sampleService;@Testpublic void testRPC(){sampleService.HelloWorld();}
}
我们启动服务producer服务,然后consumer使用Test(上述代码)
可以看到成功调用
使用端口可通过如下配置进行修改
com.alipay.sofa.rpc.bolt.port=端口号
调用方式
- 同步
见前文
- 异步
异步调用的方式下,客户端发起调用后不会等到服务端的结果,继续执行后面的业务逻辑。服务端返回的结果会被 SOFARPC 缓存,当客户端需要结果的时候,再主动调用 API 获取。
异步方式如下:
package com.consumer;import com.alipay.sofa.rpc.api.future.SofaResponseFuture;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.serviceApi.SampleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsumerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class test {@SofaReference(uniqueId = "sampleService",binding = @SofaReferenceBinding(bindingType = "bolt",invokeType = "future"))private SampleService sampleService;@Testpublic void testRPC(){try {sampleService.HelloWorld();// true表示清除String result = (String) SofaResponseFuture.getResponse(10000, true);System.out.println(result);}catch (InterruptedException e) {throw new RuntimeException(e);}}
}
注意,观察源码会发现内部是用ThreadLocalMap,如果一个线程发布了两个异步请求,但其间没有获取结果,其结果后到的一项会覆盖前一项。
我们进行如下测试。
为SampleService再添一个实例
package com.producer.serviceImpl;import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import com.serviceApi.SampleService;
import org.springframework.stereotype.Service;@Service
@SofaService(uniqueId = "sampleService2",bindings = @SofaServiceBinding(bindingType = "bolt"))
public class SampleServiceImpl2 implements SampleService {@Overridepublic String HelloWorld() {System.out.println("==========================\nhello Java!\n==========================\n");return "hello Java!";}
}
我们将测试部分改成这样的代码(睡眠了一秒为了保证前一项执行完毕)
package com.consumer;import com.alipay.sofa.rpc.api.future.SofaResponseFuture;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.serviceApi.SampleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsumerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class test {@SofaReference(uniqueId = "sampleService",binding = @SofaReferenceBinding(bindingType = "bolt",invokeType = "future"))private SampleService sampleService;@SofaReference(uniqueId = "sampleService2",binding = @SofaReferenceBinding(bindingType = "bolt",invokeType = "future"))private SampleService sampleService2;@Testpublic void testRPC(){try {sampleService.HelloWorld();Thread.sleep(1000);sampleService2.HelloWorld();String result = (String) SofaResponseFuture.getResponse(10000, true);System.out.println(result);}catch (InterruptedException e) {throw new RuntimeException(e);}}
}
服务器端没有问题
结果却输出了hello Java
如果我们去两次会报错,说明确实覆盖了。(当然如果是false就不会被清除)
public void testRPC(){try {sampleService.HelloWorld();Thread.sleep(1000);sampleService2.HelloWorld();String result = (String) SofaResponseFuture.getResponse(10000, true);String result2 = (String) SofaResponseFuture.getResponse(10000, true);System.out.println(result);System.out.println(result2);}catch (InterruptedException e) {throw new RuntimeException(e);}}
我们可以发布后交给Java原来的异步调用来管理。
Future future = SofaResponseFuture.getFuture(true);future.get(10000, TimeUnit.MILLISECONDS);
- 回调
需要实现SofaResponseCallback类
package com.consumer.callback;import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback;
import com.alipay.sofa.rpc.core.request.RequestBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;;@Configuration
public class CallbackConfiguration {Logger log = LoggerFactory.getLogger(CallbackConfiguration.class);@Bean("sampleCallback")public SofaResponseCallback getSampleCallback(){return new SofaResponseCallback() {@Overridepublic void onAppResponse(Object o, String s, RequestBase requestBase) {log.info("调用回调");log.info("{}",o.toString());}@Overridepublic void onAppException(Throwable throwable, String s, RequestBase requestBase) {System.out.println("APP错误");}@Overridepublic void onSofaException(SofaRpcException e, String s, RequestBase requestBase) {System.out.println("SOFA错误");}};}
}
SOFARPC 为设置回调接口提供了两种方式,
- Callback Class:Callback Class 的方式直接设置回调的类名,SOFARPC 会通过调用回调类的默认构造函数的方式生成回调类的实例。
- Callback Ref:Callback Ref 的方式则为用户直接提供回调类的实例。callbackRef 属性的值需要是回调类的 Bean 名称。
- 单向
当客户端发送请求后不关心服务端返回的结果时,可以使用单向的调用方式,这种方式会在发起调用后立即返回 null,并且忽略服务端的返回结果。
使用单向的方式只需要将调用方式设置为 oneway 即可,设置方式和将调用方式设置为 future 或者 callback 一样,这里不再重复讲述,可以参考上面的文档中提供的设置方式。
需要特别注意的是,由于单向的调用方式会立即返回,所以所有的超时设置在单向的情况下都是无效的。
超时控制
使用 Bolt 协议进行通信的时候,SOFARPC 的超时时间默认为 3 秒,用户可以在引用服务的时候去设置超时时间,又分别可以在服务以及方法的维度设置超时时间,SOFARPC 的超时时间的设置的单位都为毫秒。
可自行查看-Bolt 协议超时控制
- 服务维度
如果需要在发布服务的时候在服务维度设置超时时间,设置对应的 timeout 参数到对应的值即可。
@SofaReference(binding = @SofaReferenceBinding(bindingType = "bolt", timeout = 2000))
private SampleService sampleService;
- 方法维度
注解模式暂无
协议泛化调用
发布可以不变
xml无法读入时,可以尝试如下方式(*代表查找所有,无*代表使用找到的第一个)
@ImportResource({ "classpath*:rpc-starter-example.xml" })
在引用时需要配置XML
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:sofa="http://sofastack.io/schema/sofaboot"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd"default-autowire="byName"><sofa:reference jvm-first="false" id="sampleGenericServiceReference" interface="com.serviceApi.SampleService"><sofa:binding.bolt><sofa:global-attrs generic-interface="com.serviceApi.SampleService"/></sofa:binding.bolt>
</sofa:reference></beans>
@Testpublic void testRPC() {GenericService sampleGenericServiceReference = (GenericService) SpringUtil.getBean("sampleGenericServiceReference");// 需要传入方法名,方法类型,方法参数String result = sampleGenericServiceReference.$genericInvoke("HelloWorld",new String[]{},new Object[]{},String.class);System.out.println(result);}
其他规则可参考官方给出的例子
/**
* Java Bean
*/
public class People {private String name;private int age;// getters and setters
}/*** 服务方提供的接口*/
interface SampleService {String hello(String arg);People hello(People people);String[] hello(String[] args);
}/*** 客户端*/
public class ConsumerClass {GenericService genericService;public void do() {// 1. $invoke仅支持方法参数类型在当前应用的 ClassLoader 中存在的情况genericService.$invoke("hello", new String[]{ String.class.getName() }, new Object[]{"I'm an arg"});// 2. $genericInvoke支持方法参数类型在当前应用的 ClassLoader 中不存在的情况。// 2.1 构造参数GenericObject genericObject = new GenericObject("com.alipay.sofa.rpc.test.generic.bean.People"); // 构造函数中指定全路径类名genericObject.putField("name", "Lilei"); // 调用putField,指定field值genericObject.putField("age", 15);// 2.2 进行调用,不指定返回类型,返回结果类型为GenericObjectObject obj = genericService.$genericInvoke("hello", new String[]{"com.alipay.sofa.rpc.test.generic.bean.People"}, new Object[] { genericObject });Assert.assertTrue(obj.getClass == GenericObject.class);// 如果返回的是泛化的自定义对象,可以如下方式取出。String name = result.getField("name");// 2.3 进行调用,指定返回类型People people = genericService.$genericInvoke("hello", new String[]{"com.alipay.sofa.rpc.test.generic.bean.People"}, new Object[] { genericObject }, People.class);// 2.4 进行调用,参数类型是数组类型String[] result = (String[]) proxy.$genericInvoke("hello", new String[]{new String[0].getClass().getName()}, new Object[]{ new String[]{"args"} });}
}
序列化协议
SOFARPC 可以在使用 Bolt 通信协议的情况下,可以选择不同的序列化协议,
- hessian2
- protobuf
默认的情况下,SOFARPC 使用 hessian2 作为序列化协议
配置
@SofaService(bindings = @SofaServiceBinding(bindingType = "bolt",serializeType = "protobuf"))
public class SampleServiceImpl implements SampleService {
}@SofaReference(binding = @SofaReferenceBinding(bindingType = "bolt", serializeType = "protobuf"))
private SampleService sampleService;
自定义线程池
SOFARPC 支持自定义业务线程池。可以为指定服务设置一个独立的业务线程池,和 SOFARPC 自身的业务线程池是隔离的。多个服务可以共用一个独立的线程池。
SOFARPC 要求自定义线程池的类型必须是 com.alipay.sofa.rpc.server.UserThreadPool。
配置
@SofaService(bindings = {@SofaServiceBinding(bindingType = "bolt", userThreadPool = "customThreadPool")})
public class SampleServiceImpl implements SampleService {
}
2.2 RESTful
基本使用
import javax.ws.rs.GET;
import javax.ws.rs.Path;@Path("/sample")
public interface SampleService {@GET@Path("/hello")String HelloWorld();
}
@Service
@SofaService(uniqueId = "sampleService",bindings = @SofaServiceBinding(bindingType = "rest"))
public class SampleServiceImpl implements SampleService {@Overridepublic String HelloWorld() {System.out.println("==========================\nhello world!\n==========================\n");return "hello world";}
}
上述代码需放在同一项目中。
可以使用浏览器访问
http://localhost:8341/sample/hello
SOFARPC 的 RESTful 服务的默认端口为 8341。
可配置进行修改
com.alipay.sofa.rpc.rest.port=端口号
也可以用如下方式调用
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConsumerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class test {@SofaReference(uniqueId = "sampleService",binding = @SofaReferenceBinding(bindingType = "rest"))private SampleService sampleService;@Testpublic void testRPC(){System.out.println(sampleService.HelloWorld());}}
2.3 其他协议
除Http外,用法与Bolt类似。可参看协议基本使用
四、架构
附录
SOFARPC 方式快速入门
阿里云官方文档
相关文章:

SOFARPC(笔记)
文章目录 一、快速开始1.1 SOFARPC1.2 基于SOFABoot 二、注册中心三、通讯协议2.1 Bolt基本发布调用方式超时控制协议泛化调用序列化协议自定义线程池 2.2 RESTful基本使用 2.3 其他协议四、架构 附录 官方样例下载地址-sofa-boot-guides 可查看 SOFARPC 方式快速入门 一、快…...

无线上网连接及配置
目录 1. 无线上网连接及配置 1.1 无线路由器连接方式 编辑 1.2 无线路由器的基本配置 1.配置用户计算机上的IP地址 2.访问无线路由Web管理界面 1.3 WAN 口设置 1.动态 IP 2.静态 IP 1. 无线上网连接及配置 一小型公司共有20名员工。由于公司业务需要访问Internet&…...
Webpack减少打包数量和体积(Umi 3.*中)
在UMI 3.*中配置: export default defineConfig({chunks: [vendors, umi],chainWebpack: function (config: any, { webpack }: any) {config.plugin(chunkPlugin).use(webpack.optimize.LimitChunkCountPlugin, [{maxChunks: 5, // 必须大于或等于 1,此…...
python Crypto 包安装
经测试使用 pip install pycrypto安装会出现,如下所示错误: pip install pycrypto -i https://pypi.douban.com/simple/ Looking in indexes: https://pypi.douban.com/simple/ Collecting pycrypto Using cached https://pypi.doubanio.com/packages/…...

时序预测 | MATLAB实现SO-CNN-LSTM蛇群算法优化卷积长短期记忆神经网络时间序列预测
时序预测 | MATLAB实现SO-CNN-LSTM蛇群算法优化卷积长短期记忆神经网络时间序列预测 目录 时序预测 | MATLAB实现SO-CNN-LSTM蛇群算法优化卷积长短期记忆神经网络时间序列预测预测效果基本介绍程序设计学习总结参考资料 预测效果 基本介绍 时序预测 | MATLAB实现SO-CNN-LSTM蛇群…...

前端开发,怎么解决浏览器兼容性问题? - 易智编译EaseEditing
解决浏览器兼容性问题是前端开发中常见的挑战之一。不同的浏览器可能对网页元素的渲染和功能支持有所不同,因此需要采取一些策略来确保您的网页在不同浏览器上都能正常运行和呈现。以下是一些解决浏览器兼容性问题的方法和策略: 使用CSS Resetÿ…...

树莓派3B安装64位操作系统
树莓派3B安装Ubuntu MATE_树莓派3b 安装ubuntu_雨田大大的博客-CSDN博客https://blog.csdn.net/lsjackson13/article/details/92423694?utm_mediumdistribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-92423694-blog-80716098.235%5Ev38%5Ep…...

Mysql系列 - 第2天:详解mysql数据类型(重点)
这是mysql系列第2篇文章。 环境:mysql5.7.25,cmd命令中进行演示。 主要内容 介绍mysql中常用的数据类型 mysql类型和java类型对应关系 数据类型选择的一些建议 MySQL的数据类型 主要包括以下五大类 整数类型:bit、bool、tinyint、smal…...
Linux常用的运维命令
1.查看进程按内存从大到小排序 ps -e -o "%C:%p:%z:%a"|sort -k5 -nr2.查看磁盘和分区信息 # 查看挂接的分区状态mount | column -t# 查看所有分区 fdisk -l# 查看所有交换分区 swapon -s3.查看网络信息 ifconfig # 查看所有网络接口的属性iptables -L…...
【从零学习python 】50.面向对象编程中的多态应用
文章目录 多态场景代码实现多态总结 进阶案例 多态 面向对象的三大特性: 封装:这是定义类的准则,根据对象的特点,将行为和属性抽象出来,封装到一个类中。继承:这是设计类的技巧。父类与子类,主…...
实现Token刷新机制
问题场景: 开发的项目中,如果正在项目中编辑信息,编辑信息的时间的过程中token失效可能导致信息丢失怎么办? 一、解决方法 实现Token刷新机制:客户端定时刷新token,当用户的token即将过期时,可以向服务器…...
FlaUi输入账号密码
FlaUI是一个用于自动化Windows桌面应用程序的开源UI自动化库,通常用于自动化Windows应用程序的测试和操作。如果你想使用FlaUI来输入账号和密码,你需要编写一些C#或其他支持.NET的编程代码来实现这一目标。以下是一个使用FlaUI来输入账号和密码的简单示例…...

ModStartBlog v8.0.0 博客归档页面,部分组件升级
ModStart 是一个基于 Laravel 模块化极速开发框架。模块市场拥有丰富的功能应用,支持后台一键快速安装,让开发者能快的实现业务功能开发。 系统完全开源,基于 Apache 2.0 开源协议。 功能特性 丰富的模块市场,后台一键快速安装会…...

使用 PyTorch 进行高效图像分割:第 4 部分
一、说明 在这个由 4 部分组成的系列中,我们将使用 PyTorch 中的深度学习技术从头开始逐步实现图像分割。本部分将重点介绍如何实现基于视觉转换器的图像分割模型。 图 1:使用视觉转换器模型架构运行图像分割的结果。 从上到下,输入图像、地面…...

西班牙卡瓦起泡酒的风味搭配
卡瓦是一种对食物友好的西班牙起泡酒,它的制作方法和香槟一样,可以和类似的食物搭配。卡瓦食物搭配包括各种食物,从海鲜和鱼到火腿,以及不同类型的小吃,也可以将卡瓦酒与甜点、水果和奶酪搭配。 卡瓦酒是世界上最著名的…...

Java项目-苍穹外卖-Day05
文章目录 1. 新增套餐1.1 需求分析和设计1.2 代码实现1.2.1 DishController1.2.2 DishService1.2.3 DishServiceImpl1.2.4 DishMapper1.2.5 DishMapper.xml1.2.6 SetmealController1.2.7 SetmealService1.2.8 SetmealServiceImpl1.2.9 SetmealMapper1.2.10 SetmealMapper.xml1.…...

取模运算符在数组下标的应用
什么是取模运算符%? 定义: a mod b,设a、b属于正整数且b>0,如果q、r属于正整数满足aq*br,且0≤r<b,则定义: a mod b r 注意:取模运算符两侧的除数和被除数都是整数ÿ…...

Firefox(火狐),使用技巧汇总,问题处理
本文目的 说明火狐如何安装在C盘之外的盘,即定制安装路径。如何将同步功能切换到本地服务上。默认是国际服务器。安装在C盘之后如何解决,之前安装的扩展无法自动同步的问题。顺带讲解一下,火狐的一些比较好用的扩展。 安装路径定制 火狐目前…...

耐腐蚀高速数控针阀和多功能PID控制器在流量比率控制中的应用
摘要:在目前的流体比值混合控制系统中,普遍采用的是多通道闭环PID控制系统对各路流量进行准确控制后再进行混合,这种控制方式普遍存在的问题是对流量调节阀的响应速度、耐腐蚀性和线性度有很高要求。为此本文提出的第一个解决方案是采用NCNV系…...

C语言:选择+编程(每日一练Day6)
目录 编辑选择题: 题一: 题二: 题三: 题四: 题五: 编程题: 题一:至少是其他数字两倍的最大数 思路一: 思路二: 题二:两个数组的交集…...

测试微信模版消息推送
进入“开发接口管理”--“公众平台测试账号”,无需申请公众账号、可在测试账号中体验并测试微信公众平台所有高级接口。 获取access_token: 自定义模版消息: 关注测试号:扫二维码关注测试号。 发送模版消息: import requests da…...

Redis相关知识总结(缓存雪崩,缓存穿透,缓存击穿,Redis实现分布式锁,如何保持数据库和缓存一致)
文章目录 1.什么是Redis?2.为什么要使用redis作为mysql的缓存?3.什么是缓存雪崩、缓存穿透、缓存击穿?3.1缓存雪崩3.1.1 大量缓存同时过期3.1.2 Redis宕机 3.2 缓存击穿3.3 缓存穿透3.4 总结 4. 数据库和缓存如何保持一致性5. Redis实现分布式…...

基于当前项目通过npm包形式暴露公共组件
1.package.sjon文件配置 其中xh-flowable就是暴露出去的npm包名 2.创建tpyes文件夹,并新增内容 3.创建package文件夹...
工程地质软件市场:发展现状、趋势与策略建议
一、引言 在工程建设领域,准确把握地质条件是确保项目顺利推进和安全运营的关键。工程地质软件作为处理、分析、模拟和展示工程地质数据的重要工具,正发挥着日益重要的作用。它凭借强大的数据处理能力、三维建模功能、空间分析工具和可视化展示手段&…...
C++中string流知识详解和示例
一、概览与类体系 C 提供三种基于内存字符串的流,定义在 <sstream> 中: std::istringstream:输入流,从已有字符串中读取并解析。std::ostringstream:输出流,向内部缓冲区写入内容,最终取…...

自然语言处理——Transformer
自然语言处理——Transformer 自注意力机制多头注意力机制Transformer 虽然循环神经网络可以对具有序列特性的数据非常有效,它能挖掘数据中的时序信息以及语义信息,但是它有一个很大的缺陷——很难并行化。 我们可以考虑用CNN来替代RNN,但是…...
全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比
目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec? IPsec VPN 5.1 IPsec传输模式(Transport Mode) 5.2 IPsec隧道模式(Tunne…...

Linux nano命令的基本使用
参考资料 GNU nanoを使いこなすnano基础 目录 一. 简介二. 文件打开2.1 普通方式打开文件2.2 只读方式打开文件 三. 文件查看3.1 打开文件时,显示行号3.2 翻页查看 四. 文件编辑4.1 Ctrl K 复制 和 Ctrl U 粘贴4.2 Alt/Esc U 撤回 五. 文件保存与退出5.1 Ctrl …...

C++ 设计模式 《小明的奶茶加料风波》
👨🎓 模式名称:装饰器模式(Decorator Pattern) 👦 小明最近上线了校园奶茶配送功能,业务火爆,大家都在加料: 有的同学要加波霸 🟤,有的要加椰果…...

Python 实现 Web 静态服务器(HTTP 协议)
目录 一、在本地启动 HTTP 服务器1. Windows 下安装 node.js1)下载安装包2)配置环境变量3)安装镜像4)node.js 的常用命令 2. 安装 http-server 服务3. 使用 http-server 开启服务1)使用 http-server2)详解 …...