2024年最全java版gRPC实战之一:用proto生成代码(1),java面试问题大全及答案大全基础

总结

面试难免让人焦虑不安。经历过的人都懂的。但是如果你提前预测面试官要问你的问题并想出得体的回答方式,就会容易很多。

此外,都说“面试造火箭,工作拧螺丝”,那对于准备面试的朋友,你只需懂一个字:刷!

给我刷刷刷刷,使劲儿刷刷刷刷刷!今天既是来谈面试的,那就必须得来整点面试真题,这不花了我整28天,做了份“Java一线大厂高岗面试题解析合集:JAVA基础-中级-高级面试+SSM框架+分布式+性能调优+微服务+并发编程+网络+设计模式+数据结构与算法等”

image

且除了单纯的刷题,也得需准备一本【JAVA进阶核心知识手册】:JVM、JAVA集合、JAVA多线程并发、JAVA基础、Spring 原理、微服务、Netty与RPC、网络、日志、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB、Cassandra、设计模式、负载均衡、数据库、一致性算法、JAVA算法、数据结构、加密算法、分布式缓存、Hadoop、Spark、Storm、YARN、机器学习、云计算,用来查漏补缺最好不过。

image

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

核心技术

  • 为了用java发布gRPC服务,我使用的是开源库net.devh:grpc-server-spring-boot-starter

  • 在调用其他gRPC服务时用的是net.devh:grpc-client-spring-boot-starter

  • 感谢该开源库的作者Michael大神,您的智慧的简化了java程序员的gRPC开发工作,项目地址:https://github.com/yidongnan/grpc-spring-boot-starter

本篇概览

作为系列文章的开篇,本篇要做的事情如下:

  1. 明确依赖库和开发环境

  2. 新建父工程grpc-tutorials,今后《java版gRPC实战》系列的所有源码都在这个工程中

  3. 实战用proto文件自动生成java代码

明确依赖库和开发环境

整个系列文章涉及的依赖库和开发环境的情况如下:

  1. JDK:1.8.0_281

  2. gradle:6.7.1

  3. springboot:2.3.8.RELEASE

  4. grpc:1.35.0

  5. protobuf:3.14.0

  6. grpc-server-spring-boot-starter:2.11.0.RELEASE

  7. grpc-client-spring-boot-starter:2.11.0.RELEASE

  8. 操作系统:win10专业版

  9. IDEA:2021.1 (Ultimate Edition)

源码下载

  • 本篇实战中的完整源码可在GitHub下载到,地址和链接信息如下表所示(https://github.com/zq2599/blog_demos):

| 名称 | 链接 | 备注 |

| :-- | :-- | :-- |

| 项目主页 | https://github.com/zq2599/blog_demos | 该项目在GitHub上的主页 |

| git仓库地址(https) | https://github.com/zq2599/blog_demos.git | 该项目源码的仓库地址,https协议 |

| git仓库地址(ssh) | git@github.com:zq2599/blog_demos.git | 该项目源码的仓库地址,ssh协议 |

  • 这个git项目中有多个文件夹,《java版gRPC实战》系列的源码在grpc-tutorials文件夹下,如下图红框所示:

在这里插入图片描述

创建《java版gRPC实战》系列的父工程

  • 新建名为grpc-tutorials的gradle工程,前面提到的库及其版本都在此工程中处理好,build.gradle内容如下:

import java.time.OffsetDateTime

import java.time.format.DateTimeFormatter

buildscript {

repositories {

maven {

url ‘https://plugins.gradle.org/m2/’

}

// 如果有私服就在此配置,如果没有请注释掉

maven {

url ‘http://192.168.50.43:8081/repository/aliyun-proxy/’

}

// 阿里云

maven {

url ‘http://maven.aliyun.com/nexus/content/groups/public/’

}

mavenCentral()

}

ext {

// 项目版本

projectVersion = ‘1.0-SNAPSHOT’

// 依赖库的版本

grpcSpringBootStarterVersion = ‘2.11.0.RELEASE’

// grpc版本 https://github.com/grpc/grpc-java/releases

grpcVersion = ‘1.35.0’

// protobuf版本 https://github.com/protocolbuffers/protobuf/releases

protobufVersion = ‘3.14.0’

// protobuf的gradle插件版本

protobufGradlePluginVersion = ‘0.8.12’

// sprignboot版本 https://github.com/spring-projects/spring-boot/releases

springBootVersion = ‘2.3.8.RELEASE’

// springcloud版本 https://github.com/spring-cloud/spring-cloud-release/releases

springCloudVersion = ‘Hoxton.SR9’

// nacos版本 https://github.com/alibaba/spring-cloud-alibaba/releases

springCloudAlibabaNacosVersion = ‘2.2.3.RELEASE’

// security版本 https://github.com/spring-projects/spring-security-oauth/releases

springSecurityOAuthVersion = ‘2.5.0.RELEASE’

}

}

plugins {

id ‘java’

id ‘java-library’

id ‘org.springframework.boot’ version “${springBootVersion}” apply false

id ‘io.spring.dependency-management’ version ‘1.0.11.RELEASE’

id ‘net.nemerosa.versioning’ version ‘2.14.0’

id ‘com.google.protobuf’ version ‘0.8.14’

id ‘io.franzbecker.gradle-lombok’ version ‘4.0.0’ apply false

id ‘com.github.ben-manes.versions’ version ‘0.36.0’ // gradle dependencyUpdates

}

// If you attempt to build without the --scan parameter in gradle 6.0+ it will cause a build error that it can’t find

// a buildScan property to change. This avoids that problem.

if (hasProperty(‘buildScan’)) {

buildScan {

termsOfServiceUrl = ‘https://gradle.com/terms-of-service’

termsOfServiceAgree = ‘yes’

}

}

wrapper {

gradleVersion = ‘6.7.1’

}

def buildTimeAndDate = OffsetDateTime.now()

ext {

// 构建时取得当前日期和时间

buildDate = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate)

buildTime = DateTimeFormatter.ofPattern(‘HH:mm:ss.SSSZ’).format(buildTimeAndDate)

buildRevision = versioning.info.commit

}

allprojects {

apply plugin: ‘java’

apply plugin: ‘idea’

apply plugin: ‘eclipse’

apply plugin: ‘io.spring.dependency-management’

apply plugin: ‘io.franzbecker.gradle-lombok’

compileJava {

sourceCompatibility = JavaVersion.VERSION_1_8

targetCompatibility = JavaVersion.VERSION_1_8

options.encoding = ‘UTF-8’

}

compileJava.options*.compilerArgs = [

‘-Xlint:all’, ‘-Xlint:-processing’

]

// Copy LICENSE

tasks.withType(Jar) {

from(project.rootDir) {

include ‘LICENSE’

into ‘META-INF’

}

}

// 写入到MANIFEST.MF中的内容

jar {

manifest {

attributes(

‘Created-By’: “ S y s t e m . p r o p e r t i e s [ ′ j a v a . v e r s i o n ′ ] ( {System.properties['java.version']} ( System.properties[java.version]({System.properties[‘java.vendor’]} ${System.properties[‘java.vm.version’]})”.toString(),

‘Built-By’: ‘travis’,

‘Build-Date’: buildDate,

‘Build-Time’: buildTime,

‘Built-OS’: “${System.properties[‘os.name’]}”,

‘Build-Revision’: buildRevision,

‘Specification-Title’: project.name,

‘Specification-Version’: projectVersion,

‘Specification-Vendor’: ‘Will Zhao’,

‘Implementation-Title’: project.name,

‘Implementation-Version’: projectVersion,

‘Implementation-Vendor’: ‘Will Zhao’

)

}

}

repositories {

mavenCentral()

// 如果有私服就在此配置,如果没有请注释掉

maven {

url ‘http://192.168.50.43:8081/repository/aliyun-proxy/’

}

// 阿里云

maven {

url ‘http://maven.aliyun.com/nexus/content/groups/public/’

}

jcenter()

}

buildscript {

repositories {

maven { url ‘https://plugins.gradle.org/m2/’ }

}

}

}

allprojects { project ->

buildscript {

dependencyManagement {

imports {

mavenBom “org.springframework.boot:spring-boot-starter-parent:${springBootVersion}”

mavenBom “org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}”

mavenBom “com.google.protobuf:protobuf-bom:${protobufVersion}”

mavenBom “io.grpc:grpc-bom:${grpcVersion}”

mavenBom “org.junit:junit-bom:5.7.0”

}

dependencies {

dependency ‘org.projectlombok:lombok:1.16.16’

dependency ‘org.apache.commons:commons-lang3:3.11’

dependency ‘commons-collections:commons-collections:3.2.2’

dependency “net.devh:grpc-server-spring-boot-starter:${grpcSpringBootStarterVersion}”

dependency “net.devh:grpc-client-spring-boot-starter:${grpcSpringBootStarterVersion}”

}

}

ext {

micrometerVersion = dependencyManagement.importedProperties[‘micrometer.version’]

springFrameworkVersion = dependencyManagement.importedProperties[‘spring-framework.version’]

springSecurityVersion = dependencyManagement.importedProperties[‘spring-security.version’]

springCloudCommonsVersion = dependencyManagement.importedProperties[‘spring-cloud-commons.version’]

}

}

}

最后

无论是哪家公司,都很重视基础,大厂更加重视技术的深度和广度,面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,是不是能真的得到锻炼。

针对以上面试技术点,我在这里也做一些分享,希望能更好的帮助到大家。

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

技术的深度和广度,面试是一个双向选择的过程,不要抱着畏惧的心态去面试,不利于自己的发挥。同时看中的应该不止薪资,还要看你是不是真的喜欢这家公司,是不是能真的得到锻炼。

针对以上面试技术点,我在这里也做一些分享,希望能更好的帮助到大家。

[外链图片转存中…(img-FVwobnlm-1715082442656)]

[外链图片转存中…(img-X0jw6Mwk-1715082442657)]

[外链图片转存中…(img-6eb4iNAL-1715082442657)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

需要这份系统化的资料的朋友,可以点击这里获取

  • 24
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值