mule 请求者集合未在其属性中返回文件名

mule requester collection is not returning file name in it's properties

当我使用 mulerequester:request 从 SFTP 端点获取文件时,文件名在入站 属性 originalFileName 下。但是当我尝试使用 mule-requester:request-collection 文件名时却没有属于入境 属性 originalFilename.

你们能帮我用mule-requester:request-collection获取文件名吗?

mule-requester:request-collection ,
几乎没有错误 你可以在这里找到它:-Mule requester is consuming all the messages from JMS queue ...可能是一个错误
使用 mule-requester:request-collection

确保您没有遇到任何此类错误

正如您提到的,mule-requester:request-collection returns 一个 MuleMessageCollection 所以 originalFilename 入站 属性(以及所有其他)应该在每个 MuleMessage 那个集合。 我很确定您可以使用 foreach 范围处理该集合。 HTH.

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

  <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:
}

感谢这个回答

用拆分器替换 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:
}