Skip to content

Instantly share code, notes, and snippets.

View fganora's full-sized avatar

Francesco Ganora fganora

View GitHub Profile
@fganora
fganora / WorldCities.json
Last active May 19, 2020 15:36
Test JSON document for Mule DataWeave testing (World Cities)
{
"countries": [
{
"name": "Netherlands",
"continent": "Europe",
"cities": [
{
"name": "Amsterdam",
"population": "0.821",
"isCapital": true
@fganora
fganora / WorldCities.xml
Last active May 15, 2020 15:34
Test XML document for Mule DataWeave testing (World Cities)
<?xml version="1.0" encoding="UTF-8"?>
<fg:Countries xmlns:fg="http://examples.fganora.com">
<fg:Country>
<fg:Name>Netherlands</fg:Name>
<fg:Continent>Europe</fg:Continent>
<fg:Cities>
<fg:City capital="YES">
<fg:Name>Amsterdam</fg:Name>
<fg:Population>0.821</fg:Population>
</fg:City>
@fganora
fganora / gist:b3b110de703e0be6e79a69a7ab40a1bc
Created October 19, 2016 09:29
Simple Mule Caching scope example
<?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:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/core http://ww
@fganora
fganora / gist:0d0020724fe3f0ed3933bcd61f037b29
Last active April 25, 2017 07:33
Register and Get Mule Registry object
muleContext.getRegistry().registerObject("<key>", <object>)
muleContext.getRegistry().get("<key>")
@fganora
fganora / gist:7382be71bf2f258a176a10f79fd6b4d3
Created October 19, 2016 07:45
Programmatic stop/start of Mule flows (Groovy)
// stopping
def myFlow = muleContext.registry.lookupFlowConstruct('<flow name>');
if (myFlow.isStarted()) myFlow.stop()
// starting
def myFlow = muleContext.registry.lookupFlowConstruct('<flow name>');
if (!myFlow.isStarted()) myFlow.start()
@fganora
fganora / gist:baabec75fd64af0f9beaaaf9d25233eb
Created October 19, 2016 07:54
Invoking a Mule flow on application start and stop via MuleContextNotification
package com.acme;
import org.mule.DefaultMuleEvent;
import org.mule.DefaultMuleMessage;
import org.mule.MessageExchangePattern;
import org.mule.api.MuleException;
import org.mule.api.MuleRuntimeException;
import org.mule.api.context.notification.MuleContextNotificationListener;
import org.mule.config.i18n.MessageFactory;
import org.mule.construct.Flow;
@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:d17ce5a7969116076842b5345d848a6c
Created October 21, 2016 07:19
Mule: using MEL to send a payload to a VM endpoint
import org.mule.DefaultMuleMessage;
import org.mule.module.client.MuleClient;
request = new DefaultMuleMessage(payload, app.registry['_muleContext']);
MuleClient client = new MuleClient(app.registry['_muleContext']);
client.send("vm://myqueue", request);
@fganora
fganora / gist:b7f5cb85c8e981641b6a50359ecc16fe
Created October 21, 2016 08:13
Mule: MEL utiity global function to improve Logger entries
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def logMessage(loggerName, messageToLog) {
return "[" + flow.name + ":" + loggerName + "]: " + messageToLog;
}
</global-functions>
</expression-language>
</configuration>
@fganora
fganora / gist:5edf9aea69e18ba38e3a33c53be6ef55
Created October 21, 2016 09:20
Groovy: simple example of parsing and processing an XML document with XmlSlurper
def menu = new XmlSlurper().parseText(payload)
def totalPrice = 0.0
(menu.food).each {
menuItem ->
totalPrice += Double.parseDouble(menuItem.price.text())
}
totalPrice