mule requester collection不会在其属性中返回文件名

时间:2015-07-10 07:23:15

标签: mule mule-component

当我使用mulerequester:request从SFTP端点获取文件时,filename位于入站属性originalFileName下。但是当我尝试使用mule-requester:request-collection时,文件名不属于入站属性{{ 1}}。

你们可以帮助我使用originalFilename获取文件名吗?

3 个答案:

答案 0 :(得分:1)

正如您所提到的,mule-requester:request-collection会返回MuleMessageCollection,因此originalFilename入站属性(以及所有其他属性)应位于该集合的每个MuleMessage中。 我非常确定您可以使用foreach范围处理该集合。 HTH。

答案 1 :(得分:0)

mule-requester:request-collection,很少有错误 你可以在这里找到它: - Mule requester is consuming all the messages from JMS queue ......可能是一个bug 确保您没有遇到mule-requester:request-collection

的任何此类错误

答案 2 :(得分:0)

我也遇到了丢失文件名的问题。我的初始流程如下

  <file:connector name="FormDefinitonFileConnector" autoDelete="true" streaming="false"
validateConnections="true" doc:name="File" fileAge="50" />
<flow name="migrateFromFilePath">
<mulerequester:request-collection resource="file:///C:/DEV" doc:name="Request a files from a location" />
<logger message="Message before foreach: #[message]" level="INFO" doc:name="Logger" />
<foreach doc:name="For Each" collection="#[payload]">
  <logger message="originalFilename: #[message.inboundProperties['originalFilename']]-#[server.dateTime]"
    level="INFO" doc:name="Logger" />
  <logger message="Message after foreach: #[message]" level="INFO" doc:name="Logger" />
  <file:outbound-endpoint path="C:/DEV/processed" responseTimeout="10000" doc:name="File" />
</foreach>

我相信正在发生的事情是,foreach被配置为遍历有效载荷数组

<foreach doc:name="For Each" collection="#[payload]">

每个有效负载的内容不是Mule消息,而是我们加载的文件集合。

INFO  2017-05-19 11:36:18,520 [[cf_migrator].api-
httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor: 
Message before foreach: 
org.mule.DefaultMessageCollection
{
id=fe1f27d0-3c7e-11e7-856a-54391dd0f207
payload=java.util.concurrent.CopyOnWriteArrayList
correlationId=<not set>    
correlationGroup=-1
correlationSeq=-1
encoding=UTF-8
exceptionPayload=<not set>

Message properties:
    INVOCATION scoped properties:
    _ApikitResponseTransformer_AcceptedHeaders=*/*
    _ApikitResponseTransformer_apikitRouterRequest=yes
    _ApikitResponseTransformer_contractMimeTypes=[]
    INBOUND scoped properties:
    OUTBOUND scoped properties:
    SESSION scoped properties:
    }
INFO  2017-05-19 11:36:18,569 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor: Setting originalFilename: null-2017-05-19T11:36:18.563+01:00
INFO  2017-05-19 11:36:18,570 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor: Message after foreach: 
org.mule.DefaultMuleMessage
{
  id=fe20d580-3c7e-11e7-856a-54391dd0f207
  payload=[B
  correlationId=fe1f27d0-3c7e-11e7-856a-54391dd0f207
  correlationGroup=2
  correlationSeq=1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
    _ApikitResponseTransformer_AcceptedHeaders=*/*
    _ApikitResponseTransformer_apikitRouterRequest=yes
    _ApikitResponseTransformer_contractMimeTypes=[]
    counter=1
    rootMessage=<<<MuleMessage>>>
  INBOUND scoped properties:
  OUTBOUND scoped properties:
    MULE_CORRELATION_GROUP_SIZE=2
    MULE_CORRELATION_ID=fe1f27d0-3c7e-11e7-856a-54391dd0f207
    MULE_CORRELATION_SEQUENCE=1
  SESSION scoped properties:
}

感谢这个答案 Use a splitter to retain filename

用拆分器替换foreach,为每个处理的文件生成Mule消息

<file:connector name="FormDefinitonFileConnector" autoDelete="true" streaming="false"
validateConnections="true" doc:name="File" fileAge="50" />
<flow name="migrateFromFilePath">
    <mulerequester:request-collection resource="file:///C:/DEV" doc:name="Request a files from a location" />
    <logger message="Message before splitter: #[message]" level="INFO" doc:name="Logger" />
      <collection-splitter doc:name="Collection Splitter"/>
      <logger message="Setting originalFilename: #[message.inboundProperties['originalFilename']]-#[server.dateTime]"
    level="INFO" doc:name="Logger" />
      <logger message="Message after splitter: #[message]" level="INFO" doc:name="Logger" />
      <file:outbound-endpoint path="C:/DEV/processed" responseTimeout="10000" doc:name="File" />
</flow>

现在我们有一条Mule消息,其中包含文件名和文件内容作为有效负载

INFO  2017-05-19 11:50:07,240 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor:             
Message before splitter: 
org.mule.DefaultMessageCollection
{
  id=ec09b8b0-3c80-11e7-a8cf-54391dd0f207
  payload=java.util.concurrent.CopyOnWriteArrayList
  correlationId=<not set>
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
    _ApikitResponseTransformer_AcceptedHeaders=*/*
    _ApikitResponseTransformer_apikitRouterRequest=yes
    _ApikitResponseTransformer_contractMimeTypes=[]
  INBOUND scoped properties:
  OUTBOUND scoped properties:
  SESSION scoped properties:
}
INFO  2017-05-19 11:50:07,286 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor: Setting originalFilename: collectionBetweenRowsFormDef.json-2017-05-19T11:50:07.281+01:00
INFO  2017-05-19 11:50:07,288 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor: Message after splitter: 
org.mule.DefaultMuleMessage
{
  id=ec0f5e00-3c80-11e7-a8cf-54391dd0f207
  payload=[B
  correlationId=ec09b8b0-3c80-11e7-a8cf-54391dd0f207
  correlationGroup=2
  correlationSeq=1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
    _ApikitResponseTransformer_AcceptedHeaders=*/*
    _ApikitResponseTransformer_apikitRouterRequest=yes
    _ApikitResponseTransformer_contractMimeTypes=[]
  INBOUND scoped properties:
    directory=C:\DEV
    fileSize=14696
    originalDirectory=C:\DEV
    originalFilename=file1.json
    timestamp=1495120341439
  OUTBOUND scoped properties:
    MULE_CORRELATION_GROUP_SIZE=2
    MULE_CORRELATION_ID=ec09b8b0-3c80-11e7-a8cf-54391dd0f207
    MULE_CORRELATION_SEQUENCE=1
  SESSION scoped properties:
}
INFO  2017-05-19 11:50:07,350 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'FormDefinitonFileConnector.dispatcher.1900990765'. Object is: FileMessageDispatcher
INFO  2017-05-19 11:50:07,350 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'FormDefinitonFileConnector.dispatcher.1900990765'. Object is: FileMessageDispatcher
INFO  2017-05-19 11:50:07,354 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.transport.file.FileConnector: Writing file to: C:\DEV\processed\ec26b690-3c80-11e7-a8cf-54391dd0f207.dat
INFO  2017-05-19 11:50:07,357 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor:     Setting originalFilename: file1.json-2017-05-19T11:50:07.357+01:00
INFO  2017-05-19 11:50:07,357 [[cf_migrator].api-httpListenerConfig.worker.02] org.mule.api.processor.LoggerMessageProcessor:     Message after splitter: 
org.mule.DefaultMuleMessage
{
  id=ec0ffa40-3c80-11e7-a8cf-54391dd0f207
  payload=[B
  correlationId=ec09b8b0-3c80-11e7-a8cf-54391dd0f207
  correlationGroup=2
  correlationSeq=2
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
    _ApikitResponseTransformer_AcceptedHeaders=*/*
    _ApikitResponseTransformer_apikitRouterRequest=yes
    _ApikitResponseTransformer_contractMimeTypes=[]
  INBOUND scoped properties:
    directory=C:\DEV
    fileSize=54143
    originalDirectory=C:\DEV
    originalFilename=file2.json
    timestamp=1495124035101
  OUTBOUND scoped properties:
    MULE_CORRELATION_GROUP_SIZE=2
    MULE_CORRELATION_ID=ec09b8b0-3c80-11e7-a8cf-54391dd0f207
    MULE_CORRELATION_SEQUENCE=2
  SESSION scoped properties:
}