Search code examples
file-iojmsmulemule-elmule-component

File properties are lost when a file is pushed inside the JMS queue in Mule 3.5


I want to use a JMS queue to store a file and process later. I can read it from queue;I get a byte array and I can write it to a folder. But the file name is lost when I push to queue as Inbound properties are lost.

<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"/>

How can I associate the original filename back again. Is there any transformer that preserves the file name before pushing in Mule?


Solution

  • You need something like the following to read from Queue and write to a file with original file name ... A simple example here where a file is read from a flow and send to JMS Queue and the next flow takes the file out of JMS queue and write to folder with original file name :-

      <?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>
    

    Here you can receive the original file name using session variable ...