【问题标题】:Singleton Startup Mule Component/Flow单例启动 Mule 组件/流程
【发布时间】:2012-03-06 01:23:59
【问题描述】:

我在我的项目中使用了一个正在运行的 Mule 应用程序。我想做的是添加一些组件,每次启动 Mule 服务器时都会清除一些数据库表。

在这个问题上要使用什么组件?最好我希望它发生在 XML 中,而不是我必须编写的一些 Java 组件(JDBC 等)

谢谢!

【问题讨论】:

    标签: esb mule


    【解决方案1】:

    完成:

    • Mule 初始化时通知的通知侦听器,
    • 在 Groovy 中实现,因此所有代码都在 XML 配置中,
    • 用于清除数据的 JDBC 端点,因此不需要 JDBC。

    这里是配置:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-13
    • 2016-05-25
    • 2017-11-10
    • 2013-03-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 2012-10-09
    相关资源
    最近更新 更多