java - Apache Camel 自定义服务和关闭
问题描述
我已经实施了骆驼服务,但是当我尝试关闭我的路线时,这是不可能的......我必须终止该进程。我错过了什么?
首先,我创建了一个实现 camel.Service 的类:
@Service("myService")
public class MyService implements org.apache.camel.Service {
...
public WebSocket ws = null;
private Boolean isRunning=true;
public void mainCall() {
try {
.....
ws = connect();
while(isRunning) {
.....
}
} catch (IOException e) {
e.printStackTrace();
} catch (WebSocketException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void start() throws Exception {
isRunning = true;
mainCall();
}
@Override
public void stop() throws Exception {
isRunning = false;
ws.disconnect();
}
我在我的 Camel 上下文中添加我的服务,如下所示:
@Autowired
private MyService myService;
@Autowired
private CamelContext context;
@PostConstruct
public void setupCamelContext() throws Exception {
....
context.addService(myService);
}
最后我开始我的路线:
from("timer://runOnce?repeatCount=1&delay=5000")
.serviceCall("myService");
解决方案
如果您想手动停止/启动路线,请使用 HAWTIO for CAMEL。
推荐阅读
- android - 约束布局中的所有项目都移到左上角
- java - 受保护的访问说明符在 Eclipse 的子类中产生意外的编译时错误
- netlogo - Netlogo:询问“最大数量”
- javascript - javascript for循环执行顺序
- angular - 运行包含 Selenium 代码的测试时量角器出现意外控制台错误
- angular - 在本机脚本中找不到名称 com
- php - 如何根据组合框中的选择将值插入到添加到不同列的数据库表中
- c# - 如何在 Outlook 任务窗格 VSTO 中显示标签
- android - 适用于 android 的 Google ML kit Barcode Scanner 示例应用程序无法检测到条形码
- android - 显示消息后如何取消EditText的文本更改?