首先贴几个源码中的source类型。
syslog:
jdbcSource1
jdbcSource-sample:
tcp server/client source:
rabbit source:
在总结多类source的基础上总结如下:
分为两类source,一类是监听source,一类时定时拉取source.
实现监听Source
以udpsource为例需要:
1,类名注解作如下配置:
@EnableBinding(Source.class)
@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties(UdpSourceProperties.class)
2,必要成员变量
@Autowired
Source channels;
@Autowired
UdpSourceProperties properties;
3,创建一个适配器方法,需要返回值类型为 消息生产支撑适配器adapter, 即该adapter类继承MessageProducerSupport即可。
该adapter需要实现方法:
onInit(){
重写MessageProducerSupport得方法初始化方法,做些初始化操作,如:绑定channel(必须的操作),或线程池的初始化操作。
}
doStart(){
重写MessageProducerSupport得方法初始化方法,启动方法,多是线程启动方法。
}
receive(){
自定义方法,用于接收消息
}
sendMessage(){
重写MessageProducerSupport的方法,用于发送消息
}
doStop() {
重写MessageProducerSupport得方法初始化方法,停止方法,多是流的关闭,资源释放的操作。
}
4,如果需要消息转换,需要在adapter中进行消息转换
5,main方法
实现拉取source
以jdbcsource为例 需要:
1, 类名注解作如下配置:
@EnableBinding(Source.class)
@Import(TriggerConfiguration.class)
@EnableConfigurationProperties({JdbcSourceProperties.class,TriggerPropertiesMaxMessagesDefaultOne.class})
2,必要成员变量
@Autowired
@Qualifier("defaultPoller")
private PollerMetadata poller;
JdbcSourceProperties properties;
@Autowired
@Bindings(JdbcSourceConfiguration.class)
private Source source;
3,创建一个适配器方法,需要返回值类型为 拉取管道适配器adapter, 即该adapter类需要继承IntegrationObjectSupport,实现接口MessageSource
该adapter需要实现方法:
onInit(){
重写IntegrationObjectSupport的方法,初始化方法,做些初始化操作,如:线程池的初始化操作。
}
receive(){
重写MessageSource方法,用于拉取消息
}
4,创建一个拉取流方法
@Bean
public IntegrationFlow pollingFlow(){
- 运用工厂方法创建集成流生成器IntegrationFlowBuilder
- 将IntegrationFlowBuilder与outputChannel绑定
- 返回IntegrationFlow对象
}
4,如果需要消息转换,需要在adapter中进行消息转换
5,main方法
注:main方法不是必须的。如果需要重写source,建议以源码为基础进行改写。