非常古老的项目我已经继承了#2;,Apache 2.2.0并且显然从来没有做过正确的工作。
这个过程似乎已经锁定了。偶尔也永远不会完成。如果进程被终止,文件移回到入站,并重新启动它似乎工作。所以这是一个奇怪的间歇性问题。
我认为问题可能是由于自定义RoutePolicy实现;
package com.company.integration.management;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Route;
import org.apache.camel.SuspendableService;
import org.apache.camel.component.seda.SedaEndpoint;
import org.apache.camel.impl.ThrottlingInflightRoutePolicy;
import org.apache.log4j.Logger;
public class ParserInflightRoutePolicy extends ThrottlingInflightRoutePolicy {
private static Route fileRoute;
private static final int MAX_FILES_INFLIGHT = 3;
private static final int MSG_HIGH_WATERMARK = 100;
private static final int MSG_LOW_WATERMARK = 25;
private Logger logger = Logger.getLogger(getClass());
@Override
public void onExchangeBegin(Route route, Exchange exchange) {
int sedaMessagesInflight = 0;
sedaMessagesInflight = sedaQueueSize(route);
if (route.getId().equalsIgnoreCase("initialRoute")) {
fileRoute = route;
try {
if ((sedaQueueSize(route, "seda://parser") >= MAX_FILES_INFLIGHT) || (sedaMessagesInflight >= MSG_HIGH_WATERMARK)) {
if ( ! ((SuspendableService)fileRoute.getConsumer()).isSuspended() ) {
logger.error("FLOW CONTROL: stop file component");
((SuspendableService)fileRoute.getConsumer()).suspend();
}
}
}
catch (Exception ex) {
logger.error("Error stopping route", ex);
}
}
if (route.getId().equalsIgnoreCase("pricingRoute") || route.getId().equalsIgnoreCase("persistenceRoute")) {
try {
if ((sedaQueueSize(route, "seda://parser") == 0) && (sedaMessagesInflight <= MSG_LOW_WATERMARK)) {
if ( ((SuspendableService)fileRoute.getConsumer()).isSuspended() ) {
logger.error("FLOW CONTROL: start file component");
((SuspendableService)fileRoute.getConsumer()).resume();
}
}
}
catch (Exception ex) {
logger.error("Error starting route", ex);
}
}
}
int sedaQueueSize(Route route) {
int sedaMessagesInflight = 0;
CamelContext camelContext = route.getRouteContext().getCamelContext();
for (Route rte : camelContext.getRoutes()) {
Endpoint endpoint = rte.getEndpoint();
if (endpoint instanceof SedaEndpoint) {
SedaEndpoint seda = (SedaEndpoint)endpoint;
if (seda.getQueue().size() > 0) {
sedaMessagesInflight += seda.getQueue().size();
}
}
}
logger.debug("SEDA messages inflight [" + sedaMessagesInflight + "]");
return sedaMessagesInflight;
}
int sedaQueueSize(Route route, String endPointUri) {
CamelContext camelContext = route.getRouteContext().getCamelContext();
Endpoint endpoint = camelContext.getEndpoint(endPointUri);
if (endpoint instanceof SedaEndpoint) {
return ((SedaEndpoint) endpoint).getQueue().size();
}
return 0;
}
@Override
public void onExchangeDone(Route route, Exchange exchange) {
;
}
}
&#13;
请注意,此代码似乎不是线程安全的 - 没有在ThottlingInflightRoutePolicy中实现的锁定机制。这会导致间歇性的问题吗?