Zhu-tq's Blog

Find my way in this World


  • 首页

  • 归档

  • 分类

  • 标签

translate-spring-integration-overview

发表于 2018-09-12 | 阅读次数:

原文地址

iii. Overview Of Spring Integration Framework

3. Spring Integration Overview

3.3. Main Components

从垂直的角度来看,一个分层架构使关注点的分离变得简单,基于结构的层之间的调用解耦和。基于Spring的程序就是上述观点的典型案例,Spring框架和其组件为企业实践上述观点提供了强有力的基础。尽管有些相同点,基于消息的结构添加了一个水平的关注点。就像分层结构是一个非常典型和抽象的模型,消息系统也是遵循抽象的 pipes-and-filters 模型。 filters 代表任何能够生成或消费消息的组件, pipes 负责在 filters 之间传输消息用于在组件之间解耦和。需要重要说明一下的是,两个高度抽象的模型并不会相互排斥。用于 pipes 的底层消息组件仍然应该被封装成用结构来调用。同样的, filters 自身也应该用一个在应用service的上层来管理,类似于 web 层的位置

3.3.1. Message

在 Spring Integration 中,Message 是一个包装类包装任意 Java Object 同时带有用于框架的元信息。由 payload 和 header 组成。payload 可以是任何类型,headers 带着必需的信息如 id, timestamp, correlation id, return address。 headers 也用于传递值与连接的协议。例如,创建一个 Message 从一个接收到的文件,文件名应该存储在 header 用于被上传组件访问。 同样的,如果一个 Message 的内容最终打算发送到一个 outbound Mail adapter,不同的属性应该被配置成一个上传流组件的 Message header。开发者也同样可以存储任意的键值对信息在 header。

3.3.2. Message Channel(消息通道)

一个消息通道代表着 pipes-and-filters 模型中的 pipe 。生产者发送消息到通道,消费者从通道接收消息。消息通道因此解耦了消息组件,也提供了一个方便的用于拦截和监听消息的点。
一个消息通道可能是端到端的,也可以是发布/订阅模式的。端到端的通道,最多只有一个消费者可以接受到通道中的信息。发布/订阅通道,会尝试把消息广播到这个通道的所有订阅者。
端到端和发布/订阅定义了多少消费者最终会接收到消息,但是仍然有一个重要的考虑:通道应该缓存消息吗?在 Spring Integration 中,可轮训的通道能够使用队列缓存消息。缓存能够让队列能够限流被消费的消息量防止消费者过载。然而,这也添加了一些复杂程度,因为一个消费者将只能从一个可轮训的通道接收消息。另外,连接到订阅通道的消费就是简单的消息驱动。

3.3.3. Message Endpoint(消息终端)

Spring Integration 的主要目标之一就是通过 IOC 简化企业集成解决方案的开发。这意味着开发者不应该直接去实现消费者和生产者,甚至不用去构建消息和调用消息通道的发送或接受操作。而是应该专注于用PO实现业务模型。然后通过说明性的配置,你能够把你的领域代码连接到消息框架中。代表这些链接的组建是消息终端。这并不意味着你必须直接连接你已经存在的应用代码。任何真实的企业集成解决方案都会需要一些代码关注与集成关注点,例如路由和转换。重要的是去获得在集成逻辑和业务逻辑之间的关注点分离。换句话说,就像 MVC 模型对于web程序,模型应该能提供一个简单而专注的层来转换入站请求到 service 层调用,然后转换 service 层返回结果到出站层回复。

学习oracle存储过程

发表于 2018-07-09 | 阅读次数:

存储过程

存储在数据库中,供所有用户程序调用的子程序

创建存储过程

语法:

1
2
3
4
5
6
7
8
9
10
11
12
13
Create [or replace] procedure procedure_name  
[
(parameter[{in|in out}]) data_type,
(parameter[{in|in out}]) data_type,
……
]
{is|as}
Decoration section
Begin
Executable section;
Exception
Exception handlers;
End;

  • Procedure_name:存储过程的名称
  • Parameter:参数
  • in:向存储过程传递参数
  • out:从存储过程返回参数
  • in out:即可传递参数,也可返回参数
  • Data_type:参数的类型 不能够指明长度
  • As|is后声明的变量主要过程体,且不能加declare语句

创建案例解析

建立一张测试表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- 参数类型不能带长度
create or replace procedure acc_proc_order_jnl (v_ltime in varchar2,
v_rtime in varchar2) as
v_count number;
v_busi_serial varchar2(20);
v_work_date char(8);
-- 创建游标
cursor cursor_busi_serial is select busi_serial, work_date from acc_busi_acq_order_jnl where work_date >= v_ltime and work_date < v_rtime;
begin
v_count := 1;
-- for in 对游标的使用会自动开启和关闭游标
for v_pos in cursor_busi_serial loop
v_busi_serial := v_pos.busi_serial;
v_work_date := v_pos.work_date;
-- 类似于 java 中的 System.out.println
dbms_output.put_line(v_work_date);
update acc_busi_acq_order_jnl jnl set jnl.order_amt = jnl.acq_tran_amt, jnl.returned_order_amt = jnl.returned_trans_amt where jnl.busi_serial = v_busi_serial;
v_count := v_count + 1;
if mod(v_count, 100) = 0 then
commit;
dbms_output.put_line('commit');
end if;
end loop;
commit;
end acc_proc_order_jnl;

-- call调用存储过程必须带()和exec不同
call acc_proc_order_jnl('20180501', '20180701');

Gradle使用扩展属性管理依赖版本号

发表于 2018-07-05 | 阅读次数:

Maven预设变量

使用过Maven的人应该都知道,我们在Maven项目中添加依赖的一般性做法。就是打开pom.xml文件,在<dependencies>节点下添加

1
2
3
4
5
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>5.5.0</version>
</dependency>

包含坐标和版本号的内容,那么在项目中,就可以引用Lucene-coreJar包中的各种类了。但是要注意一点,这里面的版本号是以硬编码的形式存在,作为一个合格的软件开发者,要尽量在你的代码中避免硬编码的情况,方便版本管理
在Maven中使用预设变量的方式来解决:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<properties>
<version.lucene>6.0.0</version.lucene>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${version.lucene}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queries</artifactId>
<version>${version.lucene}</version>
</dependency>
</dependencies>

那么以后再遇到项目升级的情况,只需要手动修改<version.lucene>6.0.0</version.lucene>一行代码即可搞定,所有引用到该版本变量的依赖都自动升级。

Gradle单模块

同样作为后起之秀的Gradle如何优雅地解决类似问题呢?硬编码的写法如下

1
2
3
dependencies {
compile "org.apache.lucene:lucene-core:5.5.0"
}

优雅的写法①如下,修改build.gradle文件

1
2
3
4
5
6
ext {
luceneVersion = '6.5.0'
}
dependencies {
compile "org.apache.lucene:lucene-core:$luceneVersion"
}

一定要注意包含$符号时,要用双引号。在Gradle中单引号和双引号都是合法的,但是略有不同。单引号中的内容严格对应Java中的String,不对$符号进行转义。双引号的内容则和脚本语言处理有点像,如果字符中有$号的话,则它会先对$表达式求值。在Gradle中,其实还有三引号的情形,这代表什么呢?三引号中的字符串支持任意换行,比如

1
2
3
4
5
def multieLines = ''' begin
line 1
line 2
line 3
end '''

除了①,还有优雅的写法②,使用字典类型,修改build.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
ext {
javaSourceCompatibility = '1.8'
libVersions = [
junit : '4.12',
lucene: '6.5.0',
guava : '20.0'
]
}
dependencies {
compile "junit:junit:$libVersions.junit"
compile "com.google.guava:guava:$libVersions.guava"
}

Gradle多模块

当在一个根项目下有多个子模块,那么一种简单的做法是在每个子模块中都定义ext代码块,声明需要使用到的版本号变量,这样做当然可以。但是当遇到需要升级版本号的情况时,需要手动修改所有的子模块,其实还有更优雅的解决方案。就是在根项目中定义ext代码块,打开根项目的build.gradle定义

1
2
3
4
5
6
7
ext {
luceneVersion = '6.5.0'
libVersions = [
junit : '4.12',
guava : '20.0'
]
}

然后在每个子模块的build.gradle中都可以直接引用之,方式如下

1
2
3
dependencies {
compile "junit:junit:${rootProject.libVersions.junit}"
}

转载至Gradle使用扩展属性管理依赖版本号

在Ubuntu上使用SSL/TLS加密ftp服务器

发表于 2018-06-28 | 分类于 linux , ftp | 阅读次数:

生成 SSL/TLS 证书

  1. 创建子文件夹用于存储证书,sudo mkdir /etc/ssl/private
  2. 生成证书和key,sudo openssl req -x509 -nodes -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem -days 365 -newkey rsa:2048

配置vsftpd使用SSl/TLS加密通信

配置防火墙策略

1
2
3
sudo ufw allow 990/tcp
sudo ufw allow 40000:50000/tcp
sudo ufw status

修改配置文件

  • sudo vi /etc/vsftpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ssl_enable=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
#rsa_cert_file=/etc/ssl/private/ssl-cert-snakeoil.pem
#rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
require_ssl_reuse=NO
ssl_ciphers=HIGH # 选择高加密的加密方式
pasv_min_port=40000 # 被动通信的最大和最小端口
pasv_max_port=50000
debug_ssl=YES # ssl连接的日志级别提升到debug
  • 重启,sudo systemctl restart vsftpd

在Ubuntu上安装和配置ftp服务器

发表于 2018-06-28 | 分类于 linux , ftp | 阅读次数:

FTP是一个相对古老,用于两台电脑之间上传,下载文件的网络协议。然而,FTP的原始安全策略在传输数据,帐号,密码时并没有加密处理。

在Ubuntu上安装VsFTP

Ubuntu version: Ubuntu 16.04.1 LTS

  1. 首先需要安装vsftpd

    1. sudo apt-get update
    2. sudo apt-get install vsftpd
  2. 安装完成,服务器并没有自动开启,因此,我们需要手动开机,并添加到开机启动中

    1. sudo systemctl start vsftpd
    2. sudo systemctl enable vsftpd
  3. 开启ufw firewall的20和21接口

    1. sudo ufw allow 20/tcp
    2. sudo ufw allow 21/tcp
    3. sudo ufw status

配置和加固VsFTP

  1. 修改配置文件

    1. sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
    2. sudo vi /etc/vsftpd.conf
    3. 修改配置文件
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      anonymous_enable=NO             # disable  anonymous login
      local_enable=YES # permit local logins
      write_enable=YES # enable FTP commands which change the filesystem
      local_umask=022 # value of umask for file creation for local users
      dirmessage_enable=YES # enable showing of messages when users first enter a new directory
      xferlog_enable=YES # a log file will be maintained detailing uploads and downloads
      connect_from_port_20=YES # use port 20 (ftp-data) on the server machine for PORT style connections
      xferlog_std_format=YES # keep standard log file format
      listen=NO # prevent vsftpd from running in standalone mode
      listen_ipv6=YES # vsftpd will listen on an IPv6 socket instead of an IPv4 one
      pam_service_name=vsftpd # name of the PAM service vsftpd will use
      userlist_enable=YES # enable vsftpd to load a list of usernames
      tcp_wrappers=YES # turn on tcp wrappers
  2. 当userlist_deny=YES并且userlist_enable=YES时,位于用户列表的用户是被拒绝访问的,但如果userlist_deny=NO,则变成只有位于用户列表下的用户才会允许访问

    1
    2
    3
    userlist_enable=YES                   # vsftpd will load a list of usernames, from the filename given by userlist_file
    userlist_file=/etc/vsftpd.userlist # stores usernames.
    userlist_deny=NO
  3. 配置选项chroot_local_user=YES当用户登录的时候,会定位于用户根目录下,并且 VSFTPD 初始是不允许在用户根目录下写入的,需要打开配置allow_writeable_chroot=YES

    1
    2
    chroot_local_user=YES
    allow_writeable_chroot=YES
  4. 重启 sudo systemctl restart vsftpd

配置 FTP 用户的根目录

  1. 创建FTP用户

    1. sudo useradd -m -c "ftp test user" -s /bin/bash ftptest
    2. sudo passwd ftptest
    3. echo "ftptest" | sudo tee -a /etc/vsftpd.userlist
    4. cat /etc/vsftpd.userlist
  2. 处于安全要求,修改配置文件,不予许在根目录写入, #allow_writeable_chroot=YES

  3. 在用户根目录下创建一个目录,不允许其他用户写入

    1
    2
    3
    sudo mkdir /home/ftptest/ftp
    sudo chown nobody:nogroup /home/ftptest/ftp
    sudo chmod a-w /home/ftptest/ftp
  4. 创建一个目录用于写入

    1
    2
    3
    sudo mkdir /home/ftptest/ftp/files
    sudo chown -R ftptest:ftptest /home/ftptest/ftp/files
    sudo chmod -R 0770 /home/ftptest/ftp/files/
  5. 修改配置文件,重新定义用户的根目录位置

    1
    2
    user_sub_token=$USER          # inserts the username in the local root directory 
    local_root=/home/$USER/ftp # defines any users local root directory
  6. 重启,sudo systemctl restart vsftpd

Zhu tq

Zhu tq

blog

5 日志
2 分类
10 标签
GitHub
© 2018 Zhu tq
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4