如何为多个 Mule 应用程序实现一个通用的 HTTP 入口点?

How to implement a common HTTP entry point for multiple Mule applications?

我正在寻找有关为多个 HTTP Mule 应用程序实施公共入口点时的最佳实践的建议。 基本上,我们在接收 HTTP 请求的同一个 Mule 运行时上有许多 Mule 应用程序 运行。为了将它们分开,它们目前配置为监听不同的端口号。要求是应用程序可以 re-started/stopped/updated/added 而不会影响其他应用程序。现在,为每个应用程序使用一个新端口显然不是最佳做法。我认为,需要一些常见的 router/listener 将请求路由到基于 URL 路径的特定应用程序。那么,对于这样的中心入口点应用程序,是否有一些常用的设计?我在这里看到的主要问题是在添加新应用程序或更新现有应用程序时避免对其他应用程序的影响 URL?

您只需在域中配置 HTTP 连接器,并让所有应用程序使用引用它并在不同路径中侦听的 HTTP 侦听器。 看看shared resources documentation or this blog post.

如果您需要,这是代码:

mule-域-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<domain:mule-domain
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:domain="http://www.mulesoft.org/schema/mule/domain"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xsi:schemaLocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
        http://www.mulesoft.org/schema/mule/domain http://www.mulesoft.org/schema/mule/domain/current/mule-domain.xsd
        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

        <http:listener-config 
            name="shared-http-listener" 
            host="0.0.0.0" port="6541" 
            doc:name="HTTP Listener Configuration"/>

</domain:mule-domain>

并在您的 http:listener 中使用 shared-http-listener

<flow name="flow_1">
    <http:listener config-ref="shared-http-listener" path=.../>    
    ...
</flow>