是否可以在不依赖 spring 的情况下启动嵌入的 Mule3?

发布于 2025-01-02 05:19:28 字数 920 浏览 1 评论 0原文

我正在尝试使用从普通 java 应用程序嵌入的 Mule 3.2.1。该应用程序应该在存储空间有限的环境中运行。
我尝试了类似 (import, 为简洁起见省略异常):

DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  
ConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
MuleContext muleContext = muleContextFactory.createMuleContext(configBuilder);  
muleContext.start(); 

以及这样的方法:

AutoConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
DefaultMuleConfiguration configuration = new DefaultMuleConfiguration();
MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
contextBuilder.setMuleConfiguration(configuration);
MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(configbuilder, contextBuilder);
muleContext.start();

但两者都需要 spring-core、spring-beans、spring-context 和一些公共库。任何帮助都会很棒。

I am trying to use Mule 3.2.1 embedded from a plain java application. The application is suppose to run in an environment where storage space is limited.
I tried something like (import, exceptions omitted for brevity):

DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  
ConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
MuleContext muleContext = muleContextFactory.createMuleContext(configBuilder);  
muleContext.start(); 

and also this:

AutoConfigurationBuilder configBuilder = new AutoConfigurationBuilder("mule-config.xml");
DefaultMuleConfiguration configuration = new DefaultMuleConfiguration();
MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
contextBuilder.setMuleConfiguration(configuration);
MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(configbuilder, contextBuilder);
muleContext.start();

but both require spring-core, spring-beans, spring-context and some commons libraries. Any help would be great.

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

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

发布评论

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

评论(2

梦里梦着梦中梦 2025-01-09 05:19:28

如果使用XML配置,则需要Spring。

如果你不想使用 Spring,你的选择是:

  • 手动实例化并连接 Mule 内部组件,同时处理生命周期,
  • 等待 Mule DSL 发布。您可能想向 MuleSoft 询问发布日期的问题:)

如果您只想使用原始传输,即不配置任何流程或模式,您可以在没有 Spring 的情况下完成此操作,但请记住,如果 mule-core< /code> 依赖关系不会传递 Spring,但所有模块和传输都会传递。这意味着您必须使用过滤来阻止这些依赖项。

例如,要使用 HTTP 传输,您需要这些 Maven 依赖项:

<dependency>
    <groupId>org.mule</groupId>
    <artifactId>mule-core</artifactId>
    <version>3.4.0</version>
</dependency>
<dependency>
    <groupId>org.mule.transports</groupId>
    <artifactId>mule-transport-http</artifactId>
    <version>3.4.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-spring-config</artifactId>
        </exclusion>
    </exclusions>
</dependency>

有了这些依赖项,您就可以执行以下操作:

MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
MuleContext muleContext = muleContextFactory.createMuleContext(muleContextBuilder);
muleContext.start();

MuleClient client = muleContext.getClient();

MuleMessage response = client.request("http://www.google.com", 20000L);
System.out.println(response.getPayloadAsString());

muleContext.dispose();
System.exit(0);

请注意,如果这就是您使用 Mule 所做的全部操作,那么您宁愿直接使用 Apache HTTP 客户端 :)

If you use the XML configuration, you need Spring.

If you don't want to use Spring, your options are:

  • Instantiate and wire Mule internal components by hand, dealing with life cycles as well,
  • Wait until Mule DSL gets released. You may want to bug MuleSoft about a release date :)

If you only want to use raw transports, ie not configure any flow or pattern, you can do it without Spring but bear in mind that, if the mule-core dependency doesn't bring Spring transitively, all the modules and transports do. This means that you'll have to use filtering to keep these dependencies at bay.

For example to use the HTTP transport, you would need these Maven dependencies:

<dependency>
    <groupId>org.mule</groupId>
    <artifactId>mule-core</artifactId>
    <version>3.4.0</version>
</dependency>
<dependency>
    <groupId>org.mule.transports</groupId>
    <artifactId>mule-transport-http</artifactId>
    <version>3.4.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-spring-config</artifactId>
        </exclusion>
    </exclusions>
</dependency>

With this in place you then do:

MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
MuleContext muleContext = muleContextFactory.createMuleContext(muleContextBuilder);
muleContext.start();

MuleClient client = muleContext.getClient();

MuleMessage response = client.request("http://www.google.com", 20000L);
System.out.println(response.getPayloadAsString());

muleContext.dispose();
System.exit(0);

Note that if that's all you're doing with Mule, then you'd rather use the Apache HTTP Client directly :)

多情癖 2025-01-09 05:19:28
        MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
        MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
        MuleContext muleContext
        muleContextFactory.createMuleContext(muleContextBuilder);
        muleContext.start();

        // create mule client
        MuleClient client = new MuleClient(muleContext);
        // generate xml request
        String reportRequestXml = createXML(reportRequest);
        // set up message properties
        Map<String, Object> messageProperties = new HashMap<String, Object>();
        messageProperties.put("Content-Type", "application/xml");

        // send request with timeout
        MuleMessage response = client.send(crsRestUrl, reportRequestXml, messageProperties, httpTimeout);

        muleContext.stop();
        MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
        MuleContextBuilder muleContextBuilder = new DefaultMuleContextBuilder();
        MuleContext muleContext
        muleContextFactory.createMuleContext(muleContextBuilder);
        muleContext.start();

        // create mule client
        MuleClient client = new MuleClient(muleContext);
        // generate xml request
        String reportRequestXml = createXML(reportRequest);
        // set up message properties
        Map<String, Object> messageProperties = new HashMap<String, Object>();
        messageProperties.put("Content-Type", "application/xml");

        // send request with timeout
        MuleMessage response = client.send(crsRestUrl, reportRequestXml, messageProperties, httpTimeout);

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