Skip to content

Instantly share code, notes, and snippets.

View fganora's full-sized avatar

Francesco Ganora fganora

View GitHub Profile
@fganora
fganora / gist:91157c9cb0fc37f57439bee58554fcc7
Created October 19, 2016 17:56
Simple Mule Idempotent Transformer demo (idExpression = payload)
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="idempotentflowFlow">
@fganora
fganora / gist:d0f9ccecfdf3c2d0d5ba382732a9142d
Created October 19, 2016 16:57
Simple Mule HTTP to JMS flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
@fganora
fganora / gist:91b896f7c9b410eaef101e67927e1119
Last active October 20, 2016 08:56
Simple Mule flow with Groovy transformer
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:context="http://www.springframework.org/schema/context" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.
@fganora
fganora / gist:8a25ac2fa9786dff33200a0aca0ab49e
Created October 19, 2016 15:10
Mule DW: appending a footer record to CSV file using the DW "array push" operator
%dw 1.0
%output text/csv separator=";", header=false
---
payload + {filler: "***",
nRec: sizeOf payload,
filler: "***"
}
@fganora
fganora / gist:2a60b2d670634d69b04710c780ce1144
Created October 19, 2016 15:07
Mule DataWeave: example of groupBy with composite grouping key
%dw 1.0
%output application/dw
---
payload.itemlist
groupBy ((item, index) -> item.category ++ '-' ++ item.priority)
@fganora
fganora / gist:bd11ae813a4ce8634f83decef112913c
Created October 19, 2016 13:27
Mule example with simple polling (no cron scheduling, no watermark)
<flow name="periodicTriggerFlowWithUUIDPayload">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="5000"/>
<set-payload value="#[org.mule.util.UUID.getUUID()]" doc:name="Set Payload"/>
</poll>
<http:request config-ref="HTTP_Request_Configuration" path="/test/scheduler" method="POST" doc:name="HTTP"/>
</flow>
@fganora
fganora / gist:e3757ec71eff30d581d504696cc937cc
Created October 19, 2016 12:37
Mule DataWeave: example with operators: map, when ... otherwise, replace, reduce
%dw 1.0
%output application/json
---
{piatti: payload.breakfast_menu.*food map {
nome: $.name,
prezzo: (($.price) replace "\$" with ""),
ciboRiccoDiCalorie: "si" when $.calories > 700 otherwise "no"
},
totalCalories: payload.breakfast_menu.*food.calories
@fganora
fganora / gist:1bf6b38969580c355761def40191a819
Created October 19, 2016 12:35
Mule DataWeave transformation with reduce operation: total order amount computation
%dw 1.0
%output application/xml
---
{
order: {
ID: payload.orderID ++ " dated " ++ payload.orderDate,
nrLines: (sizeOf payload.orderItems) + 1,
totalOrderAmount: payload.*orderItems reduce $$ + (($.orderQuantity as :number) * ($.unitPrice as :number))
@fganora
fganora / gist:70ee12ae9c1c848604f91d85f5b7d6fc
Created October 19, 2016 11:05
Mule DataWeave: CSV to JSON mapping with multi-level grouping
%dw 1.0
%output application/json
---
payload orderBy ($.City ++ $.DeliveryDate)
groupBy ($.City ++ ',' ++ $.DeliveryDate)
pluck (
{city: ($$ splitBy ",")[0],
deliveryDate: ($$ splitBy ",")[1],
stops: ($ groupBy $.CustomerId)
pluck (
@fganora
fganora / gist:39c4d651589749844f982c16dcf630e3
Created October 19, 2016 10:00
Delaying exacution of a Mule flow based on HTTP query parameter 'delay'
delayMs = message.getInboundProperty('http.query.params')['delay'];
Thread.sleep(Integer.parseInt(delayMs));