optional

spring boot整合kafaka批量消费

不羁岁月 提交于 2020-08-13 07:48:31
spring boot整合kafaka批量消费: 配置文件: kafka: producer: bootstrap-servers: 127.0.0.1:9092 batch-size: 16785 #一次最多发送数据量 retries: 1 #发送失败后的重复发送次数 buffer-memory: 33554432 #32M批处理缓冲区 linger: 1 consumer: bootstrap-servers: 127.0.0.1:9092 auto-offset-reset: earliest #最早未被消费的offset earliest max-poll-records: 200 #批量消费一次最大拉取的数据量 enable-auto-commit: true #是否开启自动提交 auto-commit-interval: 1000 #自动提交的间隔时间 session-timeout: 20000 #连接超时时间 max-poll-interval: 15000 #手动提交设置与poll的心跳数,如果消息队列中没有消息,等待毫秒后,调用poll()方法。如果队列中有消息,立即消费消息,每次消费的消息的多少可以通过max.poll.records配置。 max-partition-fetch-bytes: 15728640 #设置拉取数据的大小,15M listener:

cassandra java client 查询结果集封装

两盒软妹~` 提交于 2020-08-13 06:45:41
cassandra 简述 Apache Cassandra 是一种分布式非关系型数据库,具有高性能、可扩展、无中心化等特征。 一种column-based数据库。 Cassandra所支持的基本数据模型。这些基本数据模型有:Column,Super Column,Column Family以及Keyspace。 依赖 <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-core</artifactId> <version>3.4.0</version> </dependency> <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-extras</artifactId> <version>3.4.0</version> <optional>true</optional> </dependency> Java 查询 使用java 的客户端查询 cassandra 时,返回值结构解析比较麻烦,故此封装了一个工具。 根据返回值信息中的列的信息,生成列与类型的关系。 queryColumns() 根据传入的Java Bean 返回 数据集。 /** *

maven 依赖出错Missing artifact com.sun:tools:jar:1.8.0

℡╲_俬逩灬. 提交于 2020-08-13 05:53:13
错误信息: Missing artifact com.sun:tools:jar:1.8.0 这个是缺少jar引起。在pom文件加入以下依赖即可 <!-- tools --> <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.8.0</version> <scope>system</scope> <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath> <optional>true</optional> </dependency> 来源: oschina 链接: https://my.oschina.net/u/1156250/blog/4424005

基于JDK8中Optional写出可读性高的代码

柔情痞子 提交于 2020-08-13 02:39:52
一、前言 JDK8中引入了函数式编程,大大提高了我们编写代码的可读性,其中Optional则是为了避免NPE而生,下面我们就来看看它是如何提高代码可读性的。 二、Optional 使用 假设我们代码里面下面DO对象: static class Wheel { public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } private String brand; } static class Car { public Wheel getWheel() { return wheel; } public void setWheel(Wheel wheel) { this.wheel = wheel; } private Wheel wheel; } static class Person { public Car getCar() { return Car; } public void setCar(Car Car) { this.Car = Car; } private Car Car; } 在不用Optional时候,如果我们想获取Person内嵌对象Wheel中的brand属性变量的值,在考虑避免NPE的情况下,代码可能如下: String

Springboot 热部署实现项目不重启调试

岁酱吖の 提交于 2020-08-12 08:02:22
1、导入相关jar包 <!-- 热部署 - 自动编译要勾选上 --> < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-devtools</ artifactId > < optional >true</ optional > </ dependency > <!-- 热部署 --> 2、修改启动插件的fork 属性 3、修改idea,启动自动编译 (1)File-Settings-Compiler-Build Project automatically (2)ctrl + shift + alt + / ,选择Registry,勾上 Compiler autoMake allow when app running 来源: oschina 链接: https://my.oschina.net/huangguangsheng/blog/4313048

半小时掌握 Python argparse

只愿长相守 提交于 2020-08-12 07:21:29
argparse 是 Python 的一个库,用于为程序提供命令行接口(Command Line Interface)。网上关于它的教程有很多,本文主要是对 How to Build Command Line Interfaces in Python With argparse 的选择性翻译+个人注解。这篇文章之所以好,首先是因为它可读性强,作者每介绍一个特性,必配合一段代码;其次是因为它全面,读完之后基本可以掌握 argparse 的主要功能。闲言少叙,书归正传。 为什么要用 argparse Linux 命令行中, ls path_to_be_listed 可以列出目标路径下的文件/文件夹。我们不妨写一个 myls.py ,用 python 实现这个功能。假如 不用 argparse 库 ,下面是一种可能的实现方式: import os import sys if len ( sys . argv ) > 2 : print ( "You have specified too many arguments" ) sys . exit () if len ( sys . argv ) < 2 : print ( "You need to specify the path to be listed" ) input_path = sys . argv [ 1 ] # sys

Spring5--@Indexed注解加快启动速度

て烟熏妆下的殇ゞ 提交于 2020-08-12 04:50:26
引 Spring Framework 5.0作为 Spring Boot 2.0 的底层核心框架,就目前已经发布的版本来看,相对于 Spring Framework 4.x 而言,注解驱动的性能提升不是那么明显。然而随着 Spring Framework 注解驱动能能力逐渐受到开发人员的关注,尤其在 Spring Boot 应用场景中,大量使用注解 @CompoentScan 扫描指定的 package,当扫描的 package 所包含的类越多时,Spring 模式注解解析的耗时就越长。对于这个问题,Spring Framework 5.0 版本引入的注解 @Indexed,为 Spring 模式注解添加索引,以提升应用启动性能。 举个栗子: @Indexed @Configuration public class WebMvcConfig implements WebMvcConfigurer {} 但是,注解 @Indexed 不能孤立地存在,需要在工程 pom.xml 中增加 org.springframework:spring-context-indexer 依赖: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-indexer</artifactId>

ifelse优化方案

佐手、 提交于 2020-08-12 04:41:32
优化 if else : https://blog.csdn.net/FBB360JAVA/article/details/103832405 参考:《阿里巴巴java编码规范》、《设计模式》(清华大学出版)、https://blog.csdn.net/mifffy_java/article/details/95201289 1、 阿里编程归约 对于控制语句,阿里归约上推荐了一种思路。【推荐】在表达异常的分支时,尽量少用 if else 方式,这种方式可以改写成: if(condition){ ... return obj; } // 接着写 else 的业务逻辑代码 说明:如果不得不使用 if()...else if()...else... 方式表达逻辑,【强制】避免后序代码维护困难,请勿超过3层。 正例:超过3层的 if else 逻辑判断代码可以使用卫语句、策略模式、状态模式等来实现,其中卫语句示例如下: public void today(){ if(isBusy()){ System.out.println("change time."); return; } if(isFree()){ System.out.println("go to travel."); return; } Sysout.out.println("stay at home. learning

Rsyslog 收集Docker日志-配置玩转

浪子不回头ぞ 提交于 2020-08-12 00:41:32
rsyslog安装没什么好说的,略过 配置文件修改前,需注意3点: 1. 先关闭selinux、firewalld等防火墙,后面再放行 2. 主机名修改,推荐 hostnamectl set-hostname server (主rsyslog服务器) hostnamectl set-hostname client (客户端rsyslog服务器) 3. 域名解析修改/etc/hosts,主服务、客户端都添加 192.168.0.229 server 192.168.0.230 client 下面直接开始配置rsyslog的配置文件 rsyslog服务端配置/etc/rsyslog.conf # rsyslog configuration file # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html # or latest version online at http://www.rsyslog.com/doc/rsyslog_conf.html # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html #### MODULES #### module(load="imuxsock" #

RabbitMQ 消费端限流、TTL、死信队列

元气小坏坏 提交于 2020-08-12 00:17:43
   消费端限流    1. 为什么要对消费端限流   假设一个场景,首先,我们 Rabbitmq 服务器积压了有上万条未处理的消息,我们随便打开一个消费者客户端,会出现这样情况: 巨量的消息瞬间全部推送过来,但是我们单个客户端无法同时处理这么多数据!   当数据量特别大的时候,我们对生产端限流肯定是不科学的,因为有时候并发量就是特别大,有时候并发量又特别少,我们无法约束生产端,这是用户的行为。所以我们应该对消费端限流,用于保持消费端的稳定,当消息数量激增的时候很有可能造成资源耗尽,以及影响服务的性能,导致系统的卡顿甚至直接崩溃。    2.限流的 api 讲解   RabbitMQ 提供了一种 qos (服务质量保证)功能,即在非自动确认消息的前提下,如果一定数目的消息(通过基于 consume 或者 channel 设置 Qos 的值)未被确认前,不进行消费新的消息。    /** * Request specific "quality of service" settings. * These settings impose limits on the amount of data the server * will deliver to consumers before requiring acknowledgements. * Thus they provide a