spring xd 参考指南(二)

Streams
The programming model for processing event streams in Spring XD is based on the well known Enterprise Integration Patterns as implemented by components(组件) in the Spring Integration project. The programming model was designed to be easy to test components.

Streams consist of the following types of modules:
Streams由以下类型的模块组成:
* Input sources
* Processing steps
* Output sinks

Input sources produce messages from a variety of sources, e.g. syslog, tcp, http.

[color=red]A message contains a payload(有效载荷) of data and a collection of key-value headers.[/color]

Messages flow through message channels from the source, through optional(可选) processing steps, to the output sink(槽).
The output sink will often write the message to a file system, such as HDFS, but may also forward the message over tcp, http, or another type of middleware.

For simple linear processing streams(对于简单的线性处理流), an analogy can be made with the UNIX pipes and filters model.
Filters represent(代表) any component that produces, processes or consumes events. This corresponds(通信) to sources, processing steps, and sinks in a stream.
Pipes represent the way data is transported between the Filters. This corresponds to the Message Channel that moves data through a stream.

http | file

The pipe symbol represents a message channel that passes data from the HTTP source to the File sink.
The message channel implementation(实现) can either be backed with a local in-memory(内存中) transport, Redis queues, or RabbitMQ.

Future releases(未来的版本) will support backing the message channel with other transports such as JMS(Java Message Service).


Note that the UNIX pipes and filter syntax is the basis for the DSL that Spring XD uses to describe simple linear(线性) flows, but we will significantly(显著) extend(增加) the syntax to cover non-linear flow in a subsequent(随后的) release.


The programming model for processing steps in a stream comes from the Spring Integration project. The central concept is one of a Message Handler class, which relies on simple coding conventions to Map incoming messages to processing methods.
它依赖于简单的编码惯例Map传入消息的处理方法
For example, using an http source you can process the body of an HTTP POST request using the following class

public class SimpleProcessor {

public String process(String payload) {
return payload.toUpperCase();
}

}

The payload of the incoming Message is passed as a string to the method process.
The contents of the payload is the body of the http request as we are using a http source.
当我们使用一个http源时,payload的内容是http请求体。
The non-void return value is used as the payload of the Message passed to the next step.
These programming conventions(编程管理) make it very easy to test your Processor component in isolation(孤立地). There are several processing components provided in Spring XD that do not require you to write any code, such as a filter and transformer(改变,变压器) that use the Spring Expression(表达) Language or Groovy.
For example, adding a processing step, such as a transformer, in a stream processing definition can be as simple as

http | transformer --expression=payload.toUpperCase() | file

Stream Deployment
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值