Apache Camel 中是否有一种方法可以通过另一条路线上的路线获取和释放锁

Is there a way in Apache Camel by which a lock can be obtained and released by a route on another route

我正在寻找一种路由可以获取和释放对另一条路由的锁定的方法,下面是我的代码片段,我正在寻找一个解决方案,其中 snmp-trap-route 和 snmp-timer-route可以获得对业务逻辑路由的独占锁,当一个正在处理时,另一个应该等到它完成。

<route id="snmp-trap-route">
<from uri="snmp:{{snmp.host}}:{{snmp.port}}?protocol=udp&amp;type=TRAP" />
<to uri="direct:snmp-main-route"/>

<route id="snmp-timer-route">
<from uri="timer://pulse?fixedRate=true&amp;period=1000" />
<to uri="direct:snmp-main-route"/>

<route id="snmp-main-route">
        <from uri="direct:snmp-main-route" />
            <choice>
                <when>
                    <simple>${property[batch.ended]} == true </simple>                      
                    <to uri="direct:transacted-endpoint" />
                </when>
                <when>
                    <simple>${property[batch.started]} == true </simple>                        
                    <to uri="direct:business-logic-endpoint" />
                </when>
                <otherwise>                 
                    <to uri="direct:business-logic-endpoint" />
                </otherwise>
            </choice>               
    </route>

<route id="business-logic-route">
        <from uri="direct:business-logic-endpoint"/>
        <setProperty propertyName="route.name">
            <constant>TestRoute</constant>
        </setProperty>
        <process ref="messageMultiplierProcessor" />
        <process ref="calculatedFieldsProcessor" />
        <process ref="tableProcessor" />                        
    </route>

<route id="transacted-route">
        <from uri="direct:transacted-endpoint"/>
        <transacted/>
        <to uri="direct:business-logic-endpoint"/>
        <onException>
            <exception>java.lang.Exception</exception>
            <handled>
                <constant>true</constant>
            </handled>
            <rollback markRollbackOnly="true"/>
        </onException>
    </route>

您可以使用队列获得相同的结果。

队列一对一地处理消息。如果您的路线在同一个 camelcontext 中,您可以使用 Seda 组件来实现此目的。否则你可以使用 activemq

<route id="snmp-trap-route">
<from uri="snmp:{{snmp.host}}:{{snmp.port}}?protocol=udp&amp;type=TRAP" />
<to uri="seda:business-logic-route"/>

<route id="snmp-timer-route">
<from uri="timer://pulse?fixedRate=true&amp;period=1000" />
<to uri="seda:business-logic-route"/>

<route id="business-logic-route">
<from uri="seda:business-logic-endpoint"/>            
<setProperty propertyName="esq.route.name">
    <constant>TestRoute</constant>
</setProperty>
<process ref="messageMultiplierProcessor" />
<process ref="calculatedFieldsProcessor" />      

这样 business-logic-route 中的下一条消息只会在 business-logic-route 完成后处理。也许这就是您要找的。