我在这样的路线上使用油门:
<throttle id="_throttle1" rejectExecution="true" timePeriodMillis="10000">
<constant>1</constant>
<bean beanType="com.company.Test"
id="_bean1" method="test"/>
</throttle>
我在我的路线中使用org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigure,可以正常工作。
我想将timePeriodMillis参数化,例如:
<throttle id="_throttle1" rejectExecution="true" timePeriodMillis="{{test}}">
<constant>1</constant>
<bean beanType="com.company.Test"
id="_bean1" method="test"/>
</throttle>
我遇到以下错误:
java.lang.NumberFormatException: For input string: "{{test}}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_162]
at java.lang.Long.parseLong(Long.java:578) ~[na:1.8.0_162]
at java.lang.Long.parseLong(Long.java:631) ~[na:1.8.0_162]
at com.sun.xml.bind.DatatypeConverterImpl._parseLong(DatatypeConverterImpl.java:133) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$19.parse(RuntimeBuiltinLeafInfoImpl.java:759) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$19.parse(RuntimeBuiltinLeafInfoImpl.java:757) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:245) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:212) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:577) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:556) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:168) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:281) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:250) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:281) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:250) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:110) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:103) ~[jaxb-core-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:161) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:132) ~[jaxb-impl-2.3.0.1.jar:2.3.0.1]
at org.apache.camel.model.ModelHelper.loadRoutesDefinition(ModelHelper.java:171) ~[camel-core-2.22.0.jar:2.22.0]
at org.apache.camel.model.ModelHelper.loadRoutesDefinition(ModelHelper.java:152) ~[camel-core-2.22.0.jar:2.22.0]
at org.apache.camel.impl.DefaultCamelContext.loadRoutesDefinition(DefaultCamelContext.java:1036) ~[camel-core-2.22.0.jar:2.22.0]
at fr.erdf.ose.ile.routes.RouteManager.loadXMLRoutes(RouteManager.java:43) ~[RouteManager.class:na]
你能帮我吗?
答案 0 :(得分:0)
根据Camel Throttle Docs,您至少可以使请求数量动态。但是,他们没有提及时间跨度。
因此,您可以在固定的毫秒数内配置 X个请求,而不必在X毫秒内配置1个请求。
<throttle timePeriodMillis="1000">
<!-- use a header to determine how many messages to throttle per sec -->
<header>throttleValue</header>
<to uri="..."/>
</throttle>
您可以尝试使用属性占位符代替消息头。
<constant>{{test}}</constant>
如果这样不起作用,您仍然可以使用属性占位符在路由中设置邮件标题。
<setHeader headerName="throttleValue">
<constant>{{test}}</constant>
</setHeader>
答案 1 :(得分:0)
请参阅有关使用属性占位符的Camel文档 http://camel.apache.org/using-propertyplaceholder.html
为XML DSL中的任何类型的属性使用属性占位符,例如,您需要将prop:
与/placeholder
命名空间一起使用,以便能够指定占位符的价值。