【问题标题】:File properties are lost when a file is pushed inside the JMS queue in Mule 3.5在 Mule 3.5 中将文件推送到 JMS 队列中时,文件属性会丢失
【发布时间】:2014-08-22 01:35:15
【问题描述】:

我想使用 JMS 队列来存储文件并稍后处理。 我可以从队列中读取它;我得到一个字节数组,我可以将它写入一个文件夹。但是当我推送到队列时文件名丢失了,因为入站属性丢失了。

<file:endpoint path="C:\Store" name="storage" responseTimeout="10000" doc:name="File"/>
<file:file-to-byte-array-transformer doc:name="File to Byte Array"/>
<jms:outbound-endpoint doc:name="Storage Queue" connector-ref="Active_MQ" queue="file.queue"/>

如何重新关联原始文件名。有没有什么转换器可以在推入 Mule 之前保留文件名?

【问题讨论】:

  • 你要做什么?? ..请解释清楚..如何使用
  • 你是对的,编辑它。因此,假设我将一个名为 sun.pdf 的文件推送到 JMS。现在我将使用入站 JMS 检索它。发生的事情是我只得到一个字节数组的文件。当我将它写入文件夹时,此文件名写为空。我想保留文件名。

标签: file-io jms mule mule-el mule-component


【解决方案1】:

按以下方式尝试 jms:outbound-endpoint。

<jms:outbound-endpoint doc:name="Storage Queue" connector-ref="Active_MQ" queue="file.queue">
          <copy-properties propertyName="*"></copy-properties>
</jms:outbound-endpoint>

这有助于您在将负载发布到 JMS 队列时保留所有入站属性。

希望这会有所帮助。

【讨论】:

  • 您好,感谢您的回复,所以我确实使用了这个东西。你能告诉我如何将此属性与我从队列中获得的字节数组相关联
  • 它与您在第一个(文件入站)流中访问文件名的方式相同#[message.inboundProperties.originalFilename] 在 JMS 入站流中您也可以以相同的方式访问文件名属性。
  • 实际上,当这个 Jms-outbound 更改为 Jms-inbound 时,我们会从入站属性中丢失值。它设置为 null。
  • 这就是我们在 JMS Outbound 中使用 copyProperties 标记的原因。此标记将所有入站属性复制到出站属性。然后在接收流(JMS INbound)中,这些属性作为入站属性出来。
  • hmm 看起来不像那样。实际上我想用你的方法来实现这一点,但没有成功,所以使用 session-vars。
【解决方案2】:

您需要类似以下内容才能从队列中读取并写入具有原始文件名的文件...这里有一个简单的示例,其中从流中读取文件并发送到 JMS 队列,下一个流将文件取出JMS 队列并使用原始文件名写入文件夹:-

  <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
    xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">

    <jms:activemq-connector name="Active_MQ"
        brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ" />
    <flow name="JMSSender" doc:name="JMSSender">
        <file:inbound-endpoint responseTimeout="10000"
            doc:name="File" path="E:\backup\test">
            <file:filename-regex-filter pattern="sun.pdf,aa.txt" caseSensitive="false" />
        </file:inbound-endpoint>

        <file:file-to-byte-array-transformer /> <!-- This is necessary otherwise the output PDF file will be corrupted .. -->

        <set-session-variable variableName="FileName" value="#[message.inboundProperties.originalFilename]" doc:name="Session Variable" />

        <jms:outbound-endpoint queue="MyQueue"  connector-ref="Active_MQ" doc:name="JMS" exchange-pattern="request-response">
        </jms:outbound-endpoint>

    </flow>


    <flow name="JMSReceiver" doc:name="JMSReceiver">

        <jms:inbound-endpoint connector-ref="Active_MQ"
            doc:name="JMS" exchange-pattern="request-response" address="jms://tcp:MyQueue">
        </jms:inbound-endpoint>

        <file:outbound-endpoint path="E:\backup\test\ss" outputPattern="#[sessionVars['FileName']]" responseTimeout="10000"
            doc:name="File" />
    </flow>


</mule>

在这里您可以使用会话变量接收原始文件名...

【讨论】:

  • 您将使用 Session 变量获得原始文件名
猜你喜欢
  • 2016-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多