单例启动 Mule 组件/流程

发布于 2025-01-05 06:20:16 字数 152 浏览 2 评论 0原文

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

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

谢谢!

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.

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)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谢绝鈎搭 2025-01-12 06:20:16

完成:

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

Done with:

  • A notification listener to be informed when Mule is initialized,
  • Implemented in Groovy so all code is in the XML config,
  • A JDBC endpoint to purge the data so no JDBC is needed.

Here is the config:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文