Esper异步http adapter集成
2017-04-12 本文已影响0人
wpb
添加http adapter相关的jar包依赖
- 上传http adapter 依赖的jar
mkdir lib-io
cp httpcore-4.0.1.jar lib-io/
cp httpcore-nio-4.0.1.jar lib-io/
cp httpclient-4.0.1.jar lib-io/
- 修改bin/setclasspath.sh
## 添加如下依赖
LIB_IO=$BASEDIR/lib-io
# Esper io
#
CLASSPATH=$CLASSPATH:$LIB/esperio-http-6.0.1.jar
CLASSPATH=$CLASSPATH:$LIB_IO/httpcore-4.0.1.jar
CLASSPATH=$CLASSPATH:$LIB_IO/httpclient-4.0.1.jar
CLASSPATH=$CLASSPATH:$LIB_IO/httpcore-nio-4.0.1.jar
##可以试下
##CLASSPATH=$CLASSPATH:$LIB_IO/*
部署epl(2选1)
直接部署epl
- vim echo.epl
module cn.wanda.tech.esper.quickstart;
@Name('Request')
create schema Request(uuid string,msg string);
@Name('Response')
create schema Response(uuid string,msg string);
@Name('Process')
On Request insert into Response select *;
@Name('Display')
select * from Response
- 部署
cp echo.epl hotdeploy/
- 确认
- 通过http://127.0.0.1:8400/esperhqapp/ ->Browse Deployments 确认加载成功
通过war包部署(方便统一管理依赖的各种udf等)
- 构建项目
git clone https://git.oschina.net/wangpeibin/esper-job.git
- 导入esper-job-quickstart
- 添加需要使用的java class和方法
- 生成war包
mvn package
- 部署
cp target/xxxxx.war hotdeploy/
- 确认
- 同上
配置输出
- 配置conf/esper-default.xml
<plugin-loader name="EsperIOHTTPAdapter" class-name="com.espertech.esperio.http.EsperIOHTTPAdapterPlugin">
<config-xml>
<esperio-http-configuration>
<!-- 输入 -->
<service name="myservice" port="8079" nio="true"/>
<get service="myservice" pattern="*"/>
<!-- 输出 -->
<request stream="Response" uri="http://127.0.0.1:8080/callback"/>
</esperio-http-configuration>
</config-xml>
</plugin-loader>
- 重启服务
sh bin/esperee.sh stop
# 可能需要等一阵 等待完全退出
sh bin/esperee.sh start
接受http adapter的输出
- 使用spring boot 快速搭建服务
- 添加 controller
@Controller
public class EventController {
private static Logger log = LoggerFactory.getLogger(EventController.class);
@ResponseBody
@RequestMapping(value = "/callback", method = RequestMethod.GET)
public void callback(HttpServletRequest request) {
log.info("callback {} {}", request.getRequestURI(), request.getQueryString());
}
}
- 启动spring boot 服务
mvn spring-boot:run
往http adapter 发送请求
wget http://127.0.0.1:8079/sendevent?stream=Request&msg=Joe
验证结果
- spring boot服务有相应的log输出