Splitter组属性注入变量参数

时间:2018-05-18 14:57:43

标签: apache apache-camel

可以将config params文件中的值注入到拆分器组属性中吗?如果是这样,这样做的正确方法是什么?谢谢!

我试过了,

<split streaming="true" >
<tokenize token="\n" group="{{noOfLines}}" />
<log message="Split Group Body: ${body}"/>
    <to uri="bean:extractHeader" />
    <to id="acceptedFileType" ref="pConsumer" /> 
</split>

<split streaming="true" >
<tokenize token="\n" group={{noOfLines}} />
<log message="Split Group Body: ${body}"/>
    <to uri="bean:extractHeader" />
    <to id="acceptedFileType" ref="pConsumer" /> 
</split>

我做错了什么?

ERROR:  'Open quote is expected for attribute "group" associated with an  element type  "tokenize".

<tokenize token="\n" group="<simple>${properties:noOfLines:500}</simple>" /> 
ERROR:  'The value of attribute "group" associated with an element type "tokenize" must not contain the '<' character.'

            <tokenize token="\n" group="${properties:noOfLines:500}" /> 

Caused by: org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '${properties:noOfLines:500}' is not a valid value for 'integer'.

2 个答案:

答案 0 :(得分:0)

我对信息和答案的追求并不深入。我发现这已经被克劳斯易卜生所包围和回答。请看看你是否满足了这个需求。

Validation error with integer property (camel)

http://camel.apache.org/using-propertyplaceholder.html

部分&#34;在XML DSL中使用任何属性的属性占位符&#34;

这是我按照这些说明做的。

添加了属性前缀命名空间       的xmlns:丙=&#34; HTTP://camel.apache.org/schema/placeholder"

然后修改了tokenize属性

<tokenize token="\n" prop:group="noOfLines" />

我使用了属性占位符

<cm:property-placeholder persistent-id="com.digital.passthru.core" />

这就像一个魅力。谢谢克劳斯。

答案 1 :(得分:0)

这对我有用。

<?xml version="1.0" encoding="UTF-8"?>
    <blueprint
      xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:prop="http://camel.apache.org/schema/placeholder"
      xmlns:camel="http://camel.apache.org/schema/blueprint"
      xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
      xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 
           http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
           http://camel.apache.org/schema/blueprint 
           http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <cm:property-placeholder persistent-id="com.ge.digital.passthru.core" />

    <bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
        <property name="deadLetterUri" value="${deadLetterQueue}"/>
        <property name="redeliveryPolicy" ref="redeliveryPolicyConfig"/>
        <property name="useOriginalMessage" value="true" />
    </bean>

    <bean id="redeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
        <property name="maximumRedeliveries" value="3"/>
        <property name="redeliveryDelay" value="5000" />

    </bean>

...

<camelContext     
  id="com.ge.digital.passthru.coreCamelContext"
  trace="true"
  xmlns="http://camel.apache.org/schema/blueprint"
  allowUseOriginalMessage="false"
  streamCache="true"
  errorHandlerRef="deadLetterErrorHandler" >

...

<route 
    id="core.predix.accept.file.type.route"
    autoStartup="true" >
    <from uri="{{fileEntranceEndpoint}}" />
    <convertBodyTo type="java.lang.String" />
    <split streaming="true" strategyRef="csvAggregationStrategy">
    <tokenize token="\n" />
      <process ref="toCsvFormat" />     <!-- passthru only we do not allow embedded commas in numeric data -->
    </split>
    <log message="CSV body: ${body}" loggingLevel="INFO"/>
    <choice>
        <when>
            <simple>${header.CamelFileName} regex '^.*\.(csv|CSV|txt|gpg)$'</simple>
            <log message="${file:name} accepted for processing..." />
            <choice>
              <when>
                <simple>${header.CamelFileName} regex '^.*\.(CSV|txt|gpg)$'</simple>
                <setHeader headerName="CamelFileName">
            <!--    <simple>${file:name.noext}.csv</simple> -->  <!-- file:name.noext.single -->
                    <simple>${file:name.noext.single}.csv</simple>
                </setHeader>
                <log message="${file:name} changed file name." />                   
              </when>
            </choice>
            <split streaming="true" >
            <tokenize token="\n" prop:group="noOfLines" />
            <log message="Split Group Body: ${body}"/>
                <to uri="bean:extractHeader" />
                <to id="acceptedFileType" ref="predixConsumer" /> 
            </split>
            <to uri="bean:extractHeader?method=cleanHeader"/>
        </when>
        <otherwise>  
            <log message="${file:name} is an unknown file type, sending to unhandled repo." loggingLevel="INFO" />
            <to uri="{{unhandledArchive}}" />
        </otherwise>
    </choice>
</route>

...  而noOfLines是一个属性

现在我在执行此操作时发现所有这些命令。 请转到下面的链接以获取XML DSL中组件的骆驼顺序

Camel DataFormat Jackson using blueprint XML DSL throws context exception