Интеграция с Spring: проблема при обновлении значения заголовка - PullRequest
0 голосов
/ 14 ноября 2018

Попытка поместить файл в несколько каталогов с помощью одного исходящего адаптера с помощью Spring -gration-file.

Чтобы добиться этого, необходимо иметь цикл перед файлом: outbound-gateway для изменения целевого каталога заголовка сообщения на каждой итерации и отправки их снова и снова на один и тот же канал, пока целевое число не уменьшится до 0.

Возможность возврата к заголовку, обогащающему канал. Но так как мы снова обогащаем значение заголовка для того же имени заголовка. значение не обновляется для имени заголовка TARGET_DIR. Не исключение также.

Хотелось бы узнать какое-нибудь решение, можно ли снова и снова обновлять значение заголовка для одного и того же имени заголовка или можно дать динамическое имя заголовка во время выполнения.

Попытался удалить заголовок TARGET_DIR, используя заголовок: фильтр во время цикла. Но не получилось.

 !-- header enricher -->
 <integration:header-enricher input-channel="filesHeaderEnricherChannel" output-channel="filesOut">
<integration:header name="TARGET_COUNT" method="getTargetCount" ref="headerEnricher"/>
<integration:header name="TARGET_DIR" method="getTargetPath" ref="headerEnricher"/>     
</integration:header-enricher>

        <integration:chain id="filesOutChain" input-channel="filesOut" output-channel="filesOutChainChannel">
            <integration:transformer expression="headers.FILE"/>
                <file:outbound-channel-adapter id="fileMover" 
                    auto-create-directory="true"
                    directory-expression="headers.TARGET_DIR"
                    mode="REPLACE">
                    <file:request-handler-advice-chain>
                        <ref bean="retryAdvice" />
                    </file:request-handler-advice-chain>
                </file:outbound-channel-adapter>    
           </integration:chain> 

     <!-- decreasing the count on each loop -->
    <!-- looping to header enricher channel again as output channel to update the target directory -->
  <integration:filter input-channel="filesOutChainChannel"  expression="headers.TARGET_COUNT != 0" output-channel="filesHeaderEnricherChannel"
                        discard-channel="filesArchiveChannel">                       
  </<integration:filter>

1 Ответ

0 голосов
/ 14 ноября 2018

Вам не хватает того факта, что header-enricher имеет дополнительную опцию:

    <xsd:attribute name="default-overwrite">
        <xsd:annotation>
            <xsd:documentation>
                Specify the default boolean value for whether to overwrite existing
                header values. This will
                only
                take effect for
                sub-elements that do not provide their own 'overwrite' attribute. If the
                'default-overwrite'
                attribute is not
                provided, then the specified header values will NOT overwrite any
                existing ones with the same
                header
                names.
                </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleType>
            <xsd:union memberTypes="xsd:boolean xsd:string" />
        </xsd:simpleType>
    </xsd:attribute>

Как и у подэлемента header есть свой собственный:

    <xsd:attribute name="overwrite">
        <xsd:annotation>
            <xsd:documentation>
                Boolean value to indicate whether this header value should overwrite an
                existing header value for
                the same name.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleType>
            <xsd:union memberTypes="xsd:boolean xsd:string" />
        </xsd:simpleType>
    </xsd:attribute>

См.также документы по этому вопросу: https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html#header-enricher

...