Netty核心技术七--Google Protobuf

news2024/9/28 5:28:51

1.编码和解码的基本介绍

  1. 编写网络应用程序时,因为数据在网络中传输的都是二进制字节码数据,在发送数据时就需要编码,接收数据时就需要解码

    image-20230621153118054

  2. codec(编解码器) 的组成部分有两个:decoder(解码器)encoder(编码器)encoder 负责把业务数据转换成字节码数据,decoder 负责把字节码数据转换成业务数据

2. Netty 本身的编码解码的机制和问题分析

  1. Netty 自身提供了一些 codec(编解码器)
  2. Netty 提供的编码器
    • StringEncoder,对字符串数据进行编码
    • ObjectEncoder,对 Java 对象进行编码
  3. Netty 提供的解码器
    • StringDecoder, 对字符串数据进行解码
    • ObjectDecoder,对 Java 对象进行解码
  4. Netty 本身自带的 ObjectDecoder 和 ObjectEncoder 可以用来实现POJO对象或各种业务对象的编码和解码,底层使用的仍是 Java 序列化技术 , 而Java 序列化技术本身效率就不高,存在如下问题
    • 无法跨语言
    • 序列化后的体积太大,是二进制编码的 5 倍多。
    • 序列化性能太低

结论:所以我们使用Protobuf

3. Protobuf

3.1 Protobuf基本介绍和使用示意图

  1. Protobuf 是 Google 发布的开源项目,全称 Google Protocol Buffers是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC[远程过程调用 remote procedure call ] 数据交换格式。

    • 目前很多公司 http+json 向 tcp+protobuf转型
  2. Protobuf 是以 message 的方式来管理数据的.

  3. 支持跨平台、跨语言,即[客户端和服务器端可以是不同的语言编写的] (支持目前绝大多数语言,例如 C++、C#、Java、python 等)

  4. 高性能,高可靠性

    • 在序列化和反序列化数据方面,Protobuf 比JSON 快得多。由于格式是二进制的,在Protobuf 中读写结构化数据所需的时间比在JSON 中要短。
  5. 使用 protobuf 编译器能自动生成代码,Protobuf 是将类的定义使用.proto文件进行描述。说明,在idea 中编写 .proto 文件时,会自动提示是否下载.ptotot 编写插件.可以让语法高亮。

  6. 然后通过 protoc.exe 编译器根据.proto 自动生成.java 文件

  7. protobuf 使用示意图

    image-20230621154614328

    1. 客户端通过protoc.exe 编译器根据.proto 自动生成.java 文件
    2. 客户端再将生成的java文件对应的对象通过ProtobufEncoder编码为二进制字节码,通过二进制进行传输
    3. 服务端拿到二进制文件再通过ProtobufDecoder解码为业务数据对象即可使用

3.2 Protobuf快速入门实例1

需求:

  1. 客户端可以发送一个Student PoJo 对象到服 务器 (通过 Protobuf 编码)
  2. 服务端能接收Student PoJo 对象,并显示信 息(通过 Protobuf 解码)

protoc-3.6.1-win32.zip官方下载地址

  1. 将我们之前写的Netty核心技术五–Netty高性能架构设计的 Netty快速入门实例-TCP服务案例直接复用

    image-20230621161944637

  2. Protobuf的使用–Java

    1. 通过Maven的方式导入Protobuf相关依赖

      <!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
      <dependency>
          <groupId>com.google.protobuf</groupId>
          <artifactId>protobuf-java</artifactId>
          <version>3.6.1</version>
      </dependency>
      
    2. protobuf定义属性各语言对照表官方文档https://protobuf.dev/programming-guides/proto3/#scalar

      .proto TypeC++ TypeJava/Kotlin Type[1]Python Type[3]Go TypeRuby TypeC# TypePHP TypeDart Type
      doubledoubledoublefloatfloat64Floatdoublefloatdouble
      floatfloatfloatfloatfloat32Floatfloatfloatdouble
      int32int32intintint32Fixnum or Bignum (as required)intintegerint
      int64int64longint/long[4]int64Bignumlonginteger/string[6]Int64
      uint32uint32int[2]int/long[4]uint32Fixnum or Bignum (as required)uintintegerint
      uint64uint64long[2]int/long[4]uint64Bignumulonginteger/string[6]Int64
      sint32int32intintint32Fixnum or Bignum (as required)intintegerint
      sint64int64longint/long[4]int64Bignumlonginteger/string[6]Int64
      fixed32uint32int[2]int/long[4]uint32Fixnum or Bignum (as required)uintintegerint
      fixed64uint64long[2]int/long[4]uint64Bignumulonginteger/string[6]Int64
      sfixed32int32intintint32Fixnum or Bignum (as required)intintegerint
      sfixed64int64longint/long[4]int64Bignumlonginteger/string[6]Int64
      boolboolbooleanboolboolTrueClass/FalseClassboolbooleanbool
      stringstringStringstr/unicode[5]stringString (UTF-8)stringstringString
      bytesstringByteStringstr (Python 2) bytes (Python 3)[]byteString (ASCII-8BIT)ByteStringstringList
    3. 新建一个.proto文件Student.proto

      syntax = "proto3"; //协议版本,因为我们的protobuf的版本是3.6.1
      option java_outer_classname = "StudentPOJO";//生成的外部类名,同时也是文件名
      //protobuf 使用message 管理数据
      message Student { //会在 StudentPOJO 外部类生成一个内部类 Student, 他是真正发送的POJO对象
        int32 id = 1; // Student 类中有 一个属性 名字为 id 类型为int32(protobuf类型) 1表示属性序号,不是值
        string name = 2;
      }
      
    4. 客户端通过protoc.exe 编译器根据.proto 自动生成.java 文件

      1. 将拷贝到 protoc.exe 同级目录或者自己配置一个环境变量

        image-20230621164132458

      2. 使用protoc.exe编译

        protoc.exe --java_out=. Student.proto
        

        image-20230621164408113

    5. 我们将 StudentPOJO.java拷贝回目录

      image-20230621164530819

      StudentPOJO有一个内部类Student,这个类才是我们传输的对象

      image-20230621164824868

    6. 编写服务端和客户端(因为我们是复用的代码,所以只需要修改一下)

3.2.1 客户端NettyClient

较之前的代码在initChannel的最前面加上了ProtoBufEncoderhandler

package site.zhourui.nioAndNetty.netty.codec;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.protobuf.ProtobufEncoder;

public class NettyClient {
    public static void main(String[] args) throws InterruptedException {
        //客户端需要一个事件循环组
        NioEventLoopGroup group = new NioEventLoopGroup();
        try {
            //创建客户端启动对象
            //注意客户端使用的不是 ServerBootstrap 而是 Bootstrap
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel socketChannel) throws Exception {
                            //在pipeline中加入 ProtoBufEncoder
                            socketChannel.pipeline().addLast("encoder", new ProtobufEncoder());
                            socketChannel.pipeline().addLast(new NettyClientHandler());
                        }
                    });
            System.out.println("客户端 ok..");
            //启动客户端去连接服务器端
            //关于 ChannelFuture 要分析,涉及到netty的异步模型
            ChannelFuture cf = bootstrap.connect("127.0.0.1", 6668).sync();
            //给关闭通道进行监听
            cf.channel().closeFuture().sync();
        }finally {
            group.shutdownGracefully();
        }

    }
}

3.2.2 客户端NettyClientHandler

  • 将重写的channelActive方法修改为发送一个StudentPOJO.Student实例对象
package site.zhourui.nioAndNetty.netty.codec;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;

public class NettyClientHandler extends ChannelInboundHandlerAdapter {
    //当通道就绪就会触发该方法
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        //发生一个Student 对象到服务器
        StudentPOJO.Student student = StudentPOJO.Student.newBuilder().setId(4).setName("智多星 吴用").build();
        ctx.pipeline().writeAndFlush(student);
    }

    //当通道有读取事件时,会触发
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf) msg;
        System.out.println("服务器回复的消息:" + buf.toString(CharsetUtil.UTF_8));
        System.out.println("服务器的地址: "+ ctx.channel().remoteAddress());
    }

    //当通道有异常时触发
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}

3.2.3 服务端NettyServer

  • 较之前的代码在initChannel的最前面加上了ProtoBufDecoderhandler
package site.zhourui.nioAndNetty.netty.codec;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;

public class NettyServer {
    public static void main(String[] args) throws InterruptedException {

        //创建BossGroup 和 WorkerGroup
        //说明
        //1. 创建两个线程组 bossGroup 和 workerGroup
        //2. bossGroup 只是处理连接请求 , 真正的和客户端业务处理,会交给 workerGroup完成
        //3. 两个都是无限循环
        //4. bossGroup 和 workerGroup 含有的子线程(NioEventLoop)的个数
        //   默认实际 cpu核数 * 2
        NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
        NioEventLoopGroup workerGroup = new NioEventLoopGroup(8);

        try {
            //创建服务器端的启动对象,配置参数
            ServerBootstrap bootstrap = new ServerBootstrap();
            //使用链式编程来进行设置
            bootstrap.group(bossGroup,workerGroup)//设置两个线程组
                    .channel(NioServerSocketChannel.class)//使用NioSocketChannel 作为服务器的通道实现
                    .option(ChannelOption.SO_BACKLOG,128)// 设置线程队列得到连接个数
                    .childOption(ChannelOption.SO_KEEPALIVE,true)//设置保持活动连接状态
                    .childHandler(new ChannelInitializer<SocketChannel>() {//创建一个通道初始化对象(匿名对象)
                        //给pipeline 设置处理器
                        @Override
                        protected void initChannel(SocketChannel socketChannel) throws Exception {
                            //可以使用一个集合管理 SocketChannel, 再推送消息时,可以将业务加入到各个channel 对应的 NIOEventLoop 的 taskQueue 或者 scheduleTaskQueue
                            System.out.println("客户socketchannel hashcode=" + socketChannel.hashCode());
                            //在pipeline加入ProtoBufDecoder
                            //指定对哪种对象进行解码
                            socketChannel.pipeline().addLast("decoder", new ProtobufDecoder(StudentPOJO.Student.getDefaultInstance()));
                            socketChannel.pipeline().addLast(new NettyServerHandler());
                        }
                    });

            System.out.println(".....服务器 is ready...");
            //绑定一个端口并且同步, 生成了一个 ChannelFuture 对象
            //启动服务器(并绑定端口)
            ChannelFuture cf = bootstrap.bind(6668).sync();

            //给cf 注册监听器,监控我们关心的事件
            cf.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture channelFuture) throws Exception {
                    if (channelFuture.isSuccess()){
                        System.out.println("监听端口 6668 成功");
                    }else {
                        System.out.println("监听端口 6668 失败");
                    }
                }
            });

            //对关闭通道进行监听
            cf.channel().closeFuture().sync();
        }finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}

3.2.4 服务端NettyServerHandler

  • ChannelInboundHandlerAdapter修改为SimpleChannelInboundHandler<StudentPOJO.Student>,这样就需要我们手动将Object对象转为StudentPOJO.Student
  • 重新channelRead0方法
    • 打印出接收到的消息
package site.zhourui.nioAndNetty.netty.codec;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

import java.util.concurrent.TimeUnit;

/*
说明
1. 我们自定义一个Handler 需要继续netty 规定好的某个HandlerAdapter(规范)
2. 这时我们自定义一个Handler , 才能称为一个handler
 */
//public class NettyServerHandler extends ChannelInboundHandlerAdapter {
public class NettyServerHandler extends SimpleChannelInboundHandler<StudentPOJO.Student> {
    //读取数据实际(这里我们可以读取客户端发送的消息)
    /*
    1. ChannelHandlerContext ctx:上下文对象, 含有 管道pipeline , 通道channel, 地址
    2. Object msg: 就是客户端发送的数据 默认Object
     */

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, StudentPOJO.Student msg) throws Exception {
        //读取从客户端发送的StudentPojo.Student
        System.out.println("客户端发送的数据 id=" + msg.getId() + " 名字=" + msg.getName());
    }


    //数据读取完毕
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        //writeAndFlush 是 write + flush
        //将数据写入到缓存,并刷新
        //一般讲,我们对这个发送的数据进行编码
        ctx.writeAndFlush(Unpooled.copiedBuffer("hello, 客户端~(>^ω^<)喵1", CharsetUtil.UTF_8));
    }
    //处理异常, 一般是需要关闭通道
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}

3.2.5 测试

  1. 启动服务端

    image-20230621173508304

  2. 启动客户端

    image-20230621173526444

    服务端接收到了客户端发送的对象

    image-20230621173541714

3.3 Protobuf快速入门实例2

需求:

  1. 客户端可以随机发送Student PoJo/ Worker PoJo 对象到服务器 (通过 Protobuf 编码)
  2. 服务端能接收Student PoJo/ Worker PoJo 对象(需要判断是哪种类型),并显示信息(通过 Protobuf 解码)

个人理解如果是每个对象都像实例1一样都生成一个.java,那么就很麻烦,所以我们将需要发送的对象(类)封装在一个.proto文件中就只需要编译一次

3.3.1 复用案例1的代码

因为实现具体功能都差不多,我们直接复用案例1的代码

image-20230621174519862

3.3.2 修改 Student.proto

较之案例1的差异:

  1. 加快解析
  2. 指定.java生成的位置
  3. protobuf 可以使用message 管理其他的message
    1. 定义三个message:MyMessage是用于管理Student,Worker
    2. MyMessage中定义枚举:在proto3 要求enum的编号从0开始
    3. 用data_type 来标识传的是哪一个枚举类型
    4. oneof:表示每次枚举类型最多只能出现其中的一个, 节省空间
  4. 将编写的Student.proto再次编译为.java,放在codec2包下
syntax = "proto3";
option optimize_for = SPEED; // 加快解析
option java_package="site.zhourui.nioAndNetty.netty.codec2";   //指定生成到哪个包下
option java_outer_classname="MyDataInfo"; // 外部类名, 文件名

//protobuf 可以使用message 管理其他的message
message MyMessage {

  //定义一个枚举类型
  enum DataType {
    StudentType = 0; //在proto3 要求enum的编号从0开始
    WorkerType = 1;
  }

  //用data_type 来标识传的是哪一个枚举类型
  DataType data_type = 1;

  //表示每次枚举类型最多只能出现其中的一个, 节省空间
  oneof dataBody {
    Student student = 2;
    Worker worker = 3;
  }

}


message Student {
  int32 id = 1;//Student类的属性
  string name = 2; //
}
message Worker {
  string name=1;
  int32 age=2;
}

3.3.3 客户端NettyClientHandler

  • 客户端端在通道连接的时候随机发送Student或Worker对象
package site.zhourui.nioAndNetty.netty.codec2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;

import java.util.Random;

public class NettyClientHandler extends ChannelInboundHandlerAdapter {
    //当通道就绪就会触发该方法
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        //随机的发送Student 或者 Workder 对象
        int random = new Random().nextInt(3);
        MyDataInfo.MyMessage myMessage = null;

        if(0 == random) { //发送Student 对象

            myMessage = MyDataInfo.MyMessage.newBuilder().setDataType(MyDataInfo.MyMessage.DataType.StudentType).setStudent(MyDataInfo.Student.newBuilder().setId(5).setName("玉麒麟 卢俊义").build()).build();
        } else { // 发送一个Worker 对象

            myMessage = MyDataInfo.MyMessage.newBuilder().setDataType(MyDataInfo.MyMessage.DataType.WorkerType).setWorker(MyDataInfo.Worker.newBuilder().setAge(20).setName("老李").build()).build();
        }

        ctx.writeAndFlush(myMessage);
    }

    //当通道有读取事件时,会触发
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf) msg;
        System.out.println("服务器回复的消息:" + buf.toString(CharsetUtil.UTF_8));
        System.out.println("服务器的地址: "+ ctx.channel().remoteAddress());
    }

    //当通道有异常时触发
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}

3.3.4 服务端NettyServer

  • 因为是发送消息是编码所以不需要修改

image-20230621180523837

3.3.5 服务端NettyServerHandler

  • 修改SimpleChannelInboundHandler泛型为MyDataInfo.MyMessage
  • channelRead0中根据dataType 来显示不同的信息
package site.zhourui.nioAndNetty.netty.codec2;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/*
说明
1. 我们自定义一个Handler 需要继续netty 规定好的某个HandlerAdapter(规范)
2. 这时我们自定义一个Handler , 才能称为一个handler
 */
//public class NettyServerHandler extends ChannelInboundHandlerAdapter {
public class NettyServerHandler extends SimpleChannelInboundHandler<MyDataInfo.MyMessage> {
    //读取数据实际(这里我们可以读取客户端发送的消息)
    /*
    1. ChannelHandlerContext ctx:上下文对象, 含有 管道pipeline , 通道channel, 地址
    2. Object msg: 就是客户端发送的数据 默认Object
     */

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyDataInfo.MyMessage msg) throws Exception {
        //根据dataType 来显示不同的信息

        MyDataInfo.MyMessage.DataType dataType = msg.getDataType();
        if(dataType == MyDataInfo.MyMessage.DataType.StudentType) {

            MyDataInfo.Student student = msg.getStudent();
            System.out.println("学生id=" + student.getId() + " 学生名字=" + student.getName());

        } else if(dataType == MyDataInfo.MyMessage.DataType.WorkerType) {
            MyDataInfo.Worker worker = msg.getWorker();
            System.out.println("工人的名字=" + worker.getName() + " 年龄=" + worker.getAge());
        } else {
            System.out.println("传输的类型不正确");
        }
    }



    //数据读取完毕
    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        //writeAndFlush 是 write + flush
        //将数据写入到缓存,并刷新
        //一般讲,我们对这个发送的数据进行编码
        ctx.writeAndFlush(Unpooled.copiedBuffer("hello, 客户端~(>^ω^<)喵1", CharsetUtil.UTF_8));
    }
    //处理异常, 一般是需要关闭通道
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }


}

3.3.6 测试

开启一次服务端,多次重启服务端模拟发送不同类型的消息

image-20230621182141403

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/671346.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【干货】Android系统定制基础篇:第十六部分(双屏异触、定时开关机与看门狗)

一、Android双屏异触-指定触摸为副屏触摸 在双屏异显产品中&#xff0c;有时候主副屏都带有触摸屏&#xff0c;并且要求主副屏触摸各自操作互不干扰。 Android 现有框架中已经支持副输入设备的逻辑&#xff0c;只是默认将所有的外部热插拔设备统一指定为副输入设备&#xff0…

XILINX 7系列FPGA封装之芯片常见封装技术详解

&#x1f3e1;《Xilinx FPGA开发指南》 目录 1&#xff0c;概述2&#xff0c;常用封装技术2.1&#xff0c;Wire-bond chip-scale2.2&#xff0c;Wire-bond fine-pitch2.3&#xff0c;Flip-chip lidless2.4&#xff0c;Ruggedized flip-chip2.5&#xff0c; Flip-chip fine-pitc…

【算法设计与分析】期末复习

文章目录 复习大纲第一章算法概述1.1算法与程序1.2 算法复杂性分析 第二章递归与分治策略分治法的基本思想递归与分治的关系&#xff1a;用分治法解决的问题的几个特征&#xff1a;例题&#xff1a; 第三章动态规划动态规划的基本思想&#xff1a;分治与动态规划算法的异同&…

mine vpn

client remote ‘whvpn.deepin.com’ 1194 auth-user-pass dev tun proto tcp nobind auth-nocache script-security 2 persist-key persist-tun user nm-openvpn group nm-openvpn -----BEGIN CERTIFICATE----- MIIDPDCCAiSgAwIBAgIUUTvTCz6BndUDTIVTBxpKL19mEMkwDQYJKoZIhvcN…

JAVA开发(spring RestFull风格Feign使用总结)

现在大多数的springboot都是使用RestFull风格的接口&#xff0c;是Feign进行远程调用。 一、Feign介绍&#xff1a; Feign是Spring Cloud Netflix组件中的一个轻量级RESTFULL的http服务客户端&#xff0c;实现了负载均衡和Rest调用的开源框架&#xff0c;封装了Ribbon和RestTe…

使用谷歌 Chrome 浏览器禁用网页 JavaScript

使用谷歌 Chrome 浏览器禁用网页 JavaScript 文章目录 使用谷歌 Chrome 浏览器禁用网页 JavaScriptI - 概述1.1 - JavaScript 的功能1.2 - 为何要禁用 JavaScript II - 禁用 JavaScript 的方式2.1 - Chrome 调试工具2.2 - Chrome 黑名单 I - 概述 1.1 - JavaScript 的功能 Web…

Fegin 中统一处理调用的结果

背景 项目中&#xff0c;微服务环境下&#xff0c;有很多时候&#xff0c;都需要调用其他服务&#xff0c;而且其他服务基本上都有一个骨架类(如下图)&#xff0c;为了不用每次调用都去判断是否成功&#xff0c;所以需要统一处理接口返回的结果 思考 跟踪代码发现&#xff0c;…

Seata Saga 模式理论学习、生产级使用示例搭建及注意事项(二) | Spring Cloud58

一、前言 通过以下系列章节&#xff1a; docker-compose 实现Seata Server高可用部署 | Spring Cloud 51 Seata AT 模式理论学习、事务隔离及部分源码解析 | Spring Cloud 52 Spring Boot集成Seata利用AT模式分布式事务示例 | Spring Cloud 53 Seata XA 模式理论学习、使用…

Dubbo服务发现原理

一、Dubbo服务发现设计 Dubbo提供的是一种Client-Based的服务发现机制&#xff0c;依赖第三方注册中心组件来协调服务发现过程&#xff0c;支持常用的注册中心如Nacos、Connsul、Zookeeper等 Dubbo服务发现机制的基本工作原理图&#xff1a; 服务发现包含提供者、消费者和注册…

MySQL 被 PG 干翻了。。

出品 | OSC开源社区&#xff08;ID&#xff1a;oschina2013) Stack Overflow 发布了 2023 年开发者调查报告&#xff0c;据称共计超过 9 万名开发者参与了此次调查。 完整报告包含了受访开发者画像&#xff0c;以及关于开发技术、AI、职业、社区等方面的内容。本文主要介绍关于…

ICC2: 工具是如何控制局部利用率的?

分析congestion map时不难发现,route congestion高的地方局部利用率往往要比周围低,这时疑问就来了,既然standard cell的分布不是均匀的,那局部再降一降彻底解决congestion问题不好嘛?工具是如何控制这种congestion driven的行为的呢? 在place_opt以及clock_opt的log里都…

Apache Atlas高级搜索语法示例

from hive_table;hive_table from hive_table where name xxx or name yyy from hive_table where name ["xxx", "yyy"] from hive_table where name LIKE *_xxx hive_db where name like "???dm?*" hive_column where table.name …

Dcat Admin 2 集成富文本编辑器 wangEditor 5

由于默认的 TinyMCE 个人不是很喜欢&#xff0c;所以替换成国产的富文本编辑器 wangEditor Dcat Admin 文档示例&#xff1a;集成富文本编辑器 wangEditor 但是官方的示例是针对 wangEditor 4 编写的&#xff0c;这里仅指出对版本 5 的差异部分 获取文件 将以下三个文件保存…

快码住! 结构体内存对齐(计算结构体大小) 干货满满!

文章目录 结构体内存对齐规则结构体大小计算为什么存在内存对齐&#xff1f;设计结构体的技巧如何修改默认对齐数&#xff1f; 结构体内存对齐规则 我们知道&#xff0c;整型变量有自己的大小&#xff0c;浮点型变量有自己的大小&#xff0c;数组也有自己的大小&#xff0c;那…

血流动力学与血压(一)--平均动脉压

平均动脉压 在血管血流动力学研究中&#xff0c;心血管系统通常被认为是一个简单的液压回路&#xff0c;由泵&#xff08;心脏&#xff09;组成&#xff0c;泵&#xff08;心脏&#xff09;有节奏地活动&#xff08;收缩 --> 舒张 --> 收缩 --> 舒张 --> 收缩…&am…

中国一重集中采购平台的建设经历和亮点

中国一重前身为第一重型机器厂&#xff0c;是“一五”期间建设156项重点工程项目之一&#xff0c;始建于1954年&#xff0c;是中央管理的涉及国家安全和国民经济命脉的国有重要骨干企业之一&#xff0c;是国家创新型试点企业、国家高新技术企业&#xff0c;拥有国家级企业技术中…

java 校园管理系统Myeclipse开发mysql数据库web结构jsp编程计算机网页项目

一、源码特点 JSP 校园管理系统 是一套完善的系统源码&#xff0c;对理解JSP java编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;以及相应配套的设计文档&#xff0c;系统主要采用B/S模式开发。 研究的基本内容是基于Web的校园管理系统&…

访问不到阿里云服务器端口

这里前台在主机上 然后访问服务器上的node后台 一直访问不到 不能连入阿里云服务器后台 连不上公网ip端口 解决方案 登录阿里云 进入云服务器 2、管理控制台 3、网络与安全——>安全组 4、安全组里面点击配置规则 5、手动添加 即可

《项目实战》构建SpringCloud alibaba项目(三、构建服务方子工程store-user-service)

系列文章目录 构建SpringCloud alibaba项目&#xff08;一、构建父工程、公共库、网关&#xff09; 构建SpringCloud alibaba项目&#xff08;二、构建微服务鉴权子工程store-authority-service&#xff09; 构建SpringCloud alibaba项目&#xff08;三、构建服务方子工程stor…

python学习——NumPy数值计算基础

目录 NumPy数值计算基础1.array创建数组及其属性2.其他创建方式3.数据类型及其转换4.生成随机数5.数组的索引和切片6.改变数组形态【案例】两个国家的数据方法一起来研究分析&#xff0c;同时保留国家的信息&#xff08;每条数据的国家来源&#xff09;&#xff0c;应该怎么办 …