MULE:: Not able to archive/delete file in an FTP location - ftp

I have defined a FTP outbound to move a file to an archive folder, the file gets archived but never gets deleted from the source location. Due to this the same files keeps getting processed again and again. Any ideas why its not removing from the source location???
<ftp:connector name="ftp-inbound" pollingFrequency="90000" validateConnections="true" doc:name="FTP"/>
<ftp:connector name="ftp-outbound" pollingFrequency="200000" validateConnections="true" doc:name="FTP"/>
<flow name="ftp_import_flow" processingStrategy="synchronous">
<ftp:inbound-endpoint host="localhost" port="21" responseTimeout="100000" doc:name="FTP" connector-ref="ftp-inbound" password="test123" path="/ftpSource/" user="admin">
<file:filename-regex-filter pattern="*.csv" caseSensitive="true"/>
<set-variable variableName="originalFileName" value="#[message.inboundProperties.originalFilename]" doc:name="Variable"/>
<logger message="FileName: #[originalFileName]" level="INFO" doc:name="Logger"/>
<reconnect frequency="100000" count="2"/>
</ftp:inbound-endpoint>
<byte-array-to-string-transformer name="byte_array_to_string" doc:name="Byte Array to String"/>
<ftp:outbound-endpoint host="localhost" port="21" connector-ref="ftp-outbound"
responseTimeout="10000" doc:name="FTP" password="test123" path="/ftpSource/archive/" user="admin">
<reconnect frequency="100000" count="2"></reconnect>
</ftp:outbound-endpoint>
<logger message="#[message]" level="DEBUG" category="ftp_flow" doc:name="Logger"></logger>
<scripting:component doc:name="ftp">
<scripting:script engine="Groovy" file="file.groovy"></scripting:script>
</scripting:component>
<logger message="#[payload]" level="DEBUG" doc:name="Logger" category="ftp_flow" />
<foreach doc:name="For Each">
<flow-ref name="insert_mysql_flow" doc:name="insert_mysql_flow" />
</foreach>
<logger message="File Process Successful" level="INFO" category="ftp_flow" doc:name="Log completion"/>
</flow>

You might want to try the option "Delete files after processing" on the Advanced tab in FTP inbound connector.

Related

Aggregate two JMS messages from two different consumers

I have two jms consumers, each in a different flow. I want to use another flow to aggregate the messages of thoe two messages. and also need to keep the correlation Ids as i need to split the payload and send back the messages.
<flow name="integration-consumer-client1" doc:name="integration-consumer-client1">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="client1.publish"/>
<logger message="Consumes Client One = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client One Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="client1" doc:name="VM"/>
</flow>
<flow name="integration-consumer-client2" doc:name="integration-consumer-client2">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="client2.publish"/>
<logger message="Consumes Client Two = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client Two Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="client2" doc:name="VM"/>
</flow>
<flow name="integration-internetsolutionsFlow1" doc:name="integration-internetsolutionsFlow1">
<scatter-gather doc:name="Scatter-Gather">
<vm:inbound-endpoint exchange-pattern="one-way" path="client1" doc:name="VM"/>
<vm:inbound-endpoint exchange-pattern="one-way" path="client2" doc:name="VM"/>
</scatter-gather>
</flow>
I tried to use the scatter gather with two inbound VMs but get the following error:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'vm:inbound-endpoint'. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/core":custom-aggregation-strategy, "http://www.mulesoft.org/schema/mule/core":threading-profile, "http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}' is expected.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
The reason of the error is integration-internetsolutionsFlow1 doesn't have any inbound endpoint ..
What you can do is following :-
Use vm:outbound-endpoint to same path from both the flow
integration-consumer-client1 and integration-consumer-client2
Then in integration-internetsolutionsFlow1
<flow name="integration-internetsolutionsFlow1" doc:name="integration-internetsolutionsFlow1">
<vm:inbound-endpoint exchange-pattern="request-response" path="Your Path" doc:name="VM" connector-ref="vmConnector" />
<logger level="INFO" message="#[message.payload]" doc:name="Logger"/>
<!-- you don't require a setter-getter here -->
</flow>
The path of outbound VM from both the flow integration-consumer-client1 and integration-consumer-client2 should be same..
You no need a scatter-gather here .. since both the flow will disptch the payload to same VM path .. It will be receive by VM inbound endpoint

How to Transform JMS message to JSON for DataMapper

I am sending the following json message to a flow via JMS:
[{"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}, {"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}]
this is my strategy:
<flow name="integration-consumer-client2" doc:name="integration-consumer-client2">
<jms:inbound-endpoint queue="client2.queue" connector-ref="Active_MQ" doc:name="JMS"/>
<logger message="Consumes Client 2 = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client 2 Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>
</flow>
<flow name="integration-consumer-client" doc:name="integration-consumer-client">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="client1.queue">
</jms:inbound-endpoint>
<logger message="Consumes Client = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Client Correlation = #[message.correlationId]" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="response" doc:name="VM"/>
</flow>
<flow name="integration-flow" doc:name="integration-flow">
<vm:inbound-endpoint path="response" doc:name="VM">
<message-properties-transformer>
<add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" />
</message-properties-transformer>
<collection-aggregator/>
</vm:inbound-endpoint>
<logger message="after vm = #[payload]" level="INFO" doc:name="Logger"/>
<request-reply doc:name="Request-Reply">
<jms:outbound-endpoint queue="queue.validation" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
</jms:outbound-endpoint>
<jms:inbound-endpoint queue="queue.validation.response" connector-ref="Active_MQ" doc:name="JMS"/>
</request-reply>
<logger message="Siebel Response in ESB = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
So two consumers messages are aggregated and then sent to another flow via the request reply using JMS. in that flow the message comes through as
[{"salesOrderId":"00001-2-3","saleName":"Car Sale","status":"processing"}, {"salesOrderId":"00004-5-6","saleName":"House Sale","status":"processing"}]
and the flow:
<jms:activemq-connector name="Active_MQ" username="admin" password="admin" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<data-mapper:config name="JSON_To_JSON" transformationGraphPath="json_to_json.grf" doc:name="JSON_To_JSON"/>
<flow name="validation-flow" doc:name="validation-flow">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="queue.validation" >
<jms:jmsmessage-to-object-transformer doc:name="JMSMessage to Object"/>
</jms:inbound-endpoint>
<logger message="Payload = #[payload]" level="INFO" doc:name="Logger"/>
<data-mapper:transform config-ref="JSON_To_JSON" doc:name="JSON To JSON"/>
<logger message="inside siebel after mapper = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
I want to send the data through a mapper because i would like to change the status to "Complete". but after the json to json mapper the result is [B#2b9f82b. How can i transform the jms message to be more readable for the mapper?
What you have is a perfectly valid bytearray. You can convert it to String again using a object-to-string-transformer or even better a byte-array-to-string-transformer.

How to use variable values from another flow on mule?

Im trying to access a value from session variable set into another flow
code:
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>
and another flow trying to print it:
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" connector-ref="" transformer-refs="transform" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint host="teste.local" path="newlocation/autocomplete?#[groovy:return req.toString();]" port="8080" user="login" password="1234" exchange-pattern="request-response" doc:name="HTTP">
</http:outbound-endpoint>
</flow>
But there is an error saing there is no variable set into that flow even when i first try to access the first url them i change to the seccond where it was supose to have the session.
-> mule version 3.4
Session variables need to be passed from one flow to another. They are serialized and deserialized on the event. You're setting it in the first flow and calling /autocomplete but the flow thats reading it is listening on /autocomplete2.
You cannot hit /autocomplete2 separately after /autocomplete and expect the session variable to be there as it was set on a different event. If you are looking to store state between separate flow invocations take a look at the mule objectstore module
http://mulesoft.github.io/mule-module-objectstore/mule/objectstore-config.html
And info on Mule object stores here:
http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores
Some example configurations here:
https://github.com/mulesoft/mule-module-objectstore/blob/master/src/test/resources/mule-config.xml
Your flow will be something like the following :-
<flow name="test" doc:name="test" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<set-session-variable variableName="message" value="test" doc:name="Set Message ID"/>
<logger message="Done #[sessionVars.message]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP"/>
</flow>
<flow name="test2" doc:name="test2" >
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/services/autocomplete2" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="req" value="#[message.inboundProperties['http.query.string']]" doc:name="Variable"/>
<logger message="#[sessionVars.message] #[sessionVars['message']] " level="INFO" doc:name="Logger"/>
</flow>

MULE_JDBC_UDATE_COUNT is returning Null value even after deleting data from Database

I have a Mule flow in which I have a Database delete operation :-
<jdbc-ee:connector name="Database_Global" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
<jdbc-ee:query key="DeleteQuery" value="delete from getData where ID=10"/>
</jdbc-ee:connector>
<flow name="DeleteFlow" doc:name="restFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="DeleteQuery" queryTimeout="-1" connector-ref="Database_Global" doc:name="Database (JDBC)"/>
<logger message="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows" level="INFO" doc:name="Logger"/>
<set-payload value="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows" doc:name="Set Payload"/>
</flow>
Now the issue is flowVars['MULE_JDBC_UDATE_COUNT'] is returning null even the row exists and is deleted from Database ... I am using Mule 3.5 anypoint studio with JDBC ee connector ..
One more issue I like to address ... I need something like :-
<choice doc:name="Choice">
<when expression="#[flowVars['MULE_JDBC_UDATE_COUNT']==null] ">
<logger message="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows... Failed!!!" level="INFO" doc:name="Logger"/>
<set-payload value="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows ...Failed!!!" doc:name="Set Payload"/>
</when>
<otherwise>
<set-payload value="Deleted Successfully !!!" doc:name="Set Payload"/>
</otherwise>
</choice>
just after the jdbc-ee:outbound-endpoint where I can display success message if row is deleted and failure message if not ... But I am getting error like :-
Root Exception stack trace:
[Error: unresolvable property or identifier: ]]
[Near : {... flowVars['MULE_JDBC_UDATE_COUNT']==null] ....}]
How can I achieve it ... Please help
You have a typo: it's MULE_JDBC_UPDATE_COUNT not MULE_JDBC_UDATE_COUNT.
Finally the working code is MULE_JDBC_UPDATE_COUNT :-
<choice doc:name="Choice">
<when expression="#[flowVars['MULE_JDBC_UPDATE_COUNT']==null] ">
<logger message="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows... Failed!!!" level="INFO" doc:name="Logger"/>
<set-payload value="Deleted #[flowVars['MULE_JDBC_UDATE_COUNT']] rows ...Failed!!!" doc:name="Set Payload"/>
</when>
<otherwise>
<set-payload value="Deleted Successfully !!!" doc:name="Set Payload"/>
</otherwise>
</choice>

Magento Connector in Mule 3.5

I have tried creating Megento connector example program as given in the Megento connector vedio link.http://www.youtube.com/watch?v=GCbuqHLCiOg
My flow is:
<magento:config name="MagentoConnector" username="${magento.username}" password="${magento.password}" address="${magento.address}" doc:name="Magento">
<magento:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</magento:config>
<flow name="ShoppingCartOPerations" doc:name="ShoppingCartOPerations">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="shoppingCartOperation" doc:name="HTTP"/>
<flow-ref name="CreateProduct" doc:name="Flow Reference"/>
<set-payload value="Product Id is #[groovy:message.getProperty('productId')]" doc:name="Set Payload"/>
</flow>
<sub-flow name="CreateProduct" doc:name="CreateProduct">
<magento:create-product config-ref="MagentoConnector" type="simple" set="1" sku="simple_sku" storeViewIdOrCode="4" doc:name="Create Product" address="https://sashistore.gostorego.com/api/v2_soap" password="gdskey" username="gdssrao">
<magento:attributes name="SampleProduct" description="TestProduct" short_description="creating sample product" weight="100" status="1" visibility="4" price="100" tax_class_id="1"/>
</magento:create-product>
<set-property propertyName="productId" value="#[payload]" doc:name="Store Product id"/>
<magento:update-inventory-stock-item config-ref="MagentoConnector" productId="#[groovy:message.getProperty('productId')]" doc:name="Update Stock">
<magento:catalog-inventory-stock-item qty="33" is_in_stock="100" min_qty="10"/>
</magento:update-inventory-stock-item>
</sub-flow>
ERROR 2014-01-29 23:48:48,521 [[magentotest].connector.http.mule.default.receiver.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: null. Type: class org.mule.api.ConnectionException
ERROR 2014-01-29 23:48:48,524 [[magentotest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
<magento:config name="MagentoConnector" username="gdssrao" password="gdskey" address="https://sashistore.gostorego.com/api/v2_soap" doc:name="Magento">
<magento:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
</magento:config>
<flow name="ShoppingCartOPerationsFlow" doc:name="ShoppingCartOPerationsFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="shoppingCartOperation" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<flow-ref name="CreateProductFlow" doc:name="Flow Reference"/>
<logger level="INFO" doc:name="Logger"/>
<set-payload value="Product Id is #[groovy:message.getProperty('productId')]" doc:name="Set Payload"/>
</flow>
<sub-flow name="CreateProductFlow" doc:name="CreateProductFlow">
<magento:create-product config-ref="MagentoConnector" type="simple" set="1" sku="simple_sku" storeViewIdOrCode="4" doc:name="Create Product">
<magento:attributes name="SampleProduct" description="TestProduct" short_description="creating sample product" weight="100" visibility="4" />
</magento:create-product>
<logger level="INFO" doc:name="Logger"/>
<set-property propertyName="productId" value="#[payload]" doc:name="Store Product id"/>
<logger level="INFO" doc:name="Logger"/>
<magento:update-inventory-stock-item config-ref="MagentoConnector" productId="#[groovy:message.getProperty('productId')]" doc:name="Update Stock">
<magento:catalog-inventory-stock-item />
</magento:update-inventory-stock-item>
</sub-flow>
You have defined your plaintext connection attributes (username, password, address) in magento:create-product and then you have them as application properties in magento:config. That does not really make sense, as you only need to define the attributes once (in the config element) when you use config-ref in the other elements. Since you are having a connection failure, I would guess that you have incorrect properties in the config element. Try using the attributes from magento:create-product, instead.
EDIT: I checked the WSDL for your Magento API, and it seems that you have incorrect address
Try using https://sashistore.gostorego.com/index.php/api/v2_soap/index/ instead.
EDIT2: I got the WSDL URL for Magento API v2 from the Magento documentation. See this page for explanation on how to get the address for Web services from WSDL.

Resources