[
https://issues.apache.org/jira/browse/CAMEL-18039?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17533341#comment-17533341
]
Karen Lease commented on CAMEL-18039:
-------------------------------------
[~yasserzamani] The route with pollEnrich(file...) calls GenericFileConsumer so
this code *is* relevant.
Also, the dummy exchange is not completely empty because it is created from the
file which is being tested against the specified name. Camel automatically sets
the headers related to the file such asĀ CamelFileAbsolutePath,
CamelFileLastModified, CamelFileLength, CamelFileName, CamelFileParent,
CamelFilePath, CamelMessageTimestamp. Those could be used in the dynamic
expression, for example to test for file name or size.
But it is true that properties set on the exchange which is passed to
pollEnrich itself are *not* available to the evaluation.
However, there is a way around this issue which is to specify the endpoint to
pollEnrich dynamically which is explained in the
[documentation|https://camel.apache.org/components/3.16.x/eips/pollEnrich-eip.html#_poll_enrich_with_dynamic_endpoints].
So assuming the exchange passed to pollEnrich is the one on which you've set
this property, the following will do what you want.
{code:java}
pollEnrich().simple("file:.?fileName=${exchangeProperty.MyCsvFileName}").{code}
> endpoint-dsl - pollEnrich or file consumer polls file alphabetically despite
> specified fileName
> -----------------------------------------------------------------------------------------------
>
> Key: CAMEL-18039
> URL: https://issues.apache.org/jira/browse/CAMEL-18039
> Project: Camel
> Issue Type: Bug
> Components: camel-core, camel-file
> Affects Versions: 3.16.0
> Reporter: Yasser Zamani
> Priority: Minor
> Fix For: 3.17.0
>
>
> I have following route
> {code:java}
> private static final String FILE_PROPERTY_NAME = "MyCsvFileName";
> private static final String FILE_NAME = "${exchangeProperty." +
> FILE_PROPERTY_NAME + "}";
> private static final String FOLDER_NAME = ".";
> from("direct:MY_CSV").routeId("MY_CSV").
> setBody(constant(FIRST_LINE)).
> transform(body().append("\r\n")).
>
> setProperty(FILE_PROPERTY_NAME).simple("MY_${messageTimestamp}.csv").
> to(file(FOLDER_NAME).fileName(FILE_NAME)).
> .
> .
> .
> pollEnrich(file(FOLDER_NAME).fileName(FILE_NAME)).
> log("The CSV file ${header." + FILE_NAME_ONLY + "} generated.
> Now uploading it...").
> {code}
> that logs following line
> {quote}The CSV file azurite-blob.sh generated. Now uploading it...
> {quote}
> We eventually realized that pollEnrich or file consumer polls file
> alphabetically despite specified fileName.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)