Done with:
- The notification listener should be informed when the Mule is initialized,
- Implemented in Groovy, so all the code is in the XML configuration,
- The JDBC endpoint is for data cleansing, so JDBC is not required.
Here is the configuration:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/3.2/mule-jdbc.xsd "> <spring:beans> <spring:bean id="jdbcDataSource" class="org.hsqldb.jdbc.JDBCDataSource"> <spring:property name="url" value="jdbc:hsqldb:mem:test-db" /> </spring:bean> <lang:groovy id="dataInitializer"> <lang:inline-script><![CDATA[ import org.mule.api.context.notification.*; import org.mule.context.notification.*; import org.mule.module.client.MuleClient; class DataInitializer implements MuleContextNotificationListener<MuleContextNotification> { public void onNotification(MuleContextNotification notification) { if (notification.action == MuleContextNotification.CONTEXT_STARTED) new MuleClient(notification.muleContext).dispatch("jdbc://initialDataPurge", null, null) } } ]]></lang:inline-script> </lang:groovy> </spring:beans> <notifications> <notification event="CONTEXT"/> <notification-listener ref="dataInitializer"/> </notifications> <jdbc:connector name="jdbcConnector" dataSource-ref="jdbcDataSource"> <jdbc:query key="initialDataPurge" value="DELETE FROM test;" /> </jdbc:connector> </mule>
source share