单例启动M子组件/流 [英] Singleton Startup Mule Component/Flow

查看:75
本文介绍了单例启动M子组件/流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a running Mule application I am using in my project. What I would like to do is add some component that would clear some database table everytime the Mule server is started up.

在这件事上将使用什么组件?最好是我希望它发生在XML上,而不是我必须编写的某些Java组件(JDBC之类)

What would be the component to use in this matter? Preferably I'd like it to happen from XML and not some Java component I have to write (JDBC and such)

谢谢!

推荐答案

完成于:

  • 初始化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>

这篇关于单例启动M子组件/流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆