我需要查看克劳斯的答案,但为了获得快速而肮脏的 UI,我采用了不同的方法。
我使用的是 Spring MVC 3.1.X,并为我的应用程序中的各种项目提供了一个管理控制台。我编写了一个控制器来显示路由及其状态,并提供了根据需要启动和停止路由的链接。这是一些代码:
@Controller
public class CamelController {
private static final Log LOG = LogFactory.getLog(CamelController.class);
@Autowired
@Qualifier("myCamelContextID")
private CamelContext camelContext;
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
public String dashboard(Model model) {
if (LOG.isDebugEnabled()) {
LOG.debug("camel context is suspended : " + camelContext.isSuspended());
}
List<Route> routes = camelContext.getRoutes();
List<RouteStatus> routeStatuses = new ArrayList<RouteStatus>();
for (Route r : routes) {
RouteStatus rs = new RouteStatus();
rs.setId(r.getId());
rs.setServiceStatus(camelContext.getRouteStatus(r.getId()));
routeStatuses.add(rs);
}
model.addAttribute("routeStatuses", routeStatuses);
return "dashboard";
}
@RequestMapping(value = "/dashboard/{routeId}/start", method = RequestMethod.GET)
public String startRoute(@PathVariable String routeId) {
try {
camelContext.startRoute(routeId);
if (LOG.isDebugEnabled()) {
LOG.debug("camel context is starting route [" + routeId + "]");
}
} catch (Exception e) {
LOG.error("failed to start camel context [" + camelContext + "]");
}
return "redirect:/dashboard";
}
@RequestMapping(value = "/dashboard/{routeId}/stop", method = RequestMethod.GET)
public String stopRoute(@PathVariable String routeId) {
try {
camelContext.stopRoute(routeId);
if (LOG.isDebugEnabled()) {
LOG.debug("camel context is stopping route [" + routeId + "]");
}
} catch (Exception e) {
LOG.error("failed to stop camel context [" + camelContext + "]");
}
return "redirect:/dashboard";
}
}
}
我做了一个小 POJO:
public class RouteStatus {
private String id;
private ServiceStatus serviceStatus;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ServiceStatus getServiceStatus() {
return serviceStatus;
}
public void setServiceStatus(ServiceStatus serviceStatus) {
this.serviceStatus = serviceStatus;
}
}