Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在主/从或故障转移关系中使用Mule实例_Mule - Fatal编程技术网

在主/从或故障转移关系中使用Mule实例

在主/从或故障转移关系中使用Mule实例,mule,Mule,我有两个Mule实例订阅了队列中的同一主题,但我只希望每条消息使用一次 我可以通过将消息汇集到唯一队列并从那里进行处理来实现这一点,但为了降低操作复杂性,我希望设置在每个Mule实例上运行的消息使用者流,使其遵从其中一个实例 这类似于ActiveMQ故障切换设置,其中一次只有一个实例在运行,空闲实例只有在运行的实例无法响应时才会唤醒,或者类似于主/从配置,在主/从配置中,我会将一个实例的命令授予其他实例。或者像是实例间而不是实例内的VM传输 这需要在没有任何Mule Enterprise Edi

我有两个Mule实例订阅了队列中的同一主题,但我只希望每条消息使用一次

我可以通过将消息汇集到唯一队列并从那里进行处理来实现这一点,但为了降低操作复杂性,我希望设置在每个Mule实例上运行的消息使用者流,使其遵从其中一个实例

这类似于ActiveMQ故障切换设置,其中一次只有一个实例在运行,空闲实例只有在运行的实例无法响应时才会唤醒,或者类似于主/从配置,在主/从配置中,我会将一个实例的命令授予其他实例。或者像是实例间而不是实例内的VM传输


这需要在没有任何Mule Enterprise Edition组件的情况下完成,这些组件仅依赖于使用Mule版本3.4的Mule Community Edition组件。或3.5.

我找不到一种方便的内置方法来实现这一点。相反,我假设每个mule实例将在单独的框中运行,并使用server.host值确定哪个实例进行处理:

<mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis" 
    xmlns="http://www.mulesoft.org/schema/mule/core"  
    version="CE-3.5.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/3.4/mule-redis.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">

    <!-- define redis instance -->
    <redis:config name="redis-instance" />

    <flow name="topicConsumer">
        <!-- listen to redis channel (topic) -->
        <redis:subscribe config-ref="redis-instance">
            <redis:channels>
                <redis:channel>topic.channel</redis:channel>
            </redis:channels>
        </redis:subscribe>

        <!-- save original payload (message from Redis) -->
        <set-session-variable variableName="redisPayload" value="#[payload]" />

        <!-- select processor -->
        <flow-ref name="topicProcessorSelector"/>

        <choice>
            <when expression="#[sessionVars['subscriberProcessor'] == server.host]">
                <logger level="INFO" message="processing on #[server.host]"/>
            </when>
            <otherwise>
                <logger level="INFO" message="take no action"/>
            </otherwise>
        </choice>
    </flow>

    <flow name="topicProcessorSelector" processingStrategy="synchronous">
        <!-- get key -->
        <redis:get config-ref="redis-instance" 
            key="topic_processor"/>

        <!-- if no key, then add this instance as the processor -->
        <choice>
            <when expression="#[payload instanceof org.mule.transport.NullPayload]">
                <!-- set key -->
                <redis:set config-ref="redis-instance" 
                    key="topic_processor"
                    expire="10"
                    value="#[server.host]">
                </redis:set>
                <set-session-variable variableName="subscriberProcessor" value="#[server.host]" />
            </when>
            <otherwise>
                <!-- use existing key -->
                <byte-array-to-string-transformer/>
                <set-session-variable variableName="subscriberProcessor" value="#[payload]" />
            </otherwise>
        </choice>
    </flow>
</mule>