![](/img/trans.png)
[英]@SendTo not working in JMS (ActiveMQ integration) with Spring Boot
[英]JMS & Spring Integration, removing the dependency on having a ActiveMQ instance
我最近將一些日志記錄設置為AcitveMQ的即發即忘服務,以便該應用程序可以將消息發送至“ ActivityLoggingChannel”,而不必處理日志記錄的交叉問題。
一切都發送到ActivityLoggingGateway,它只是具有默認通道的接口。 然后,這會向Pojo(動態路由器)查詢通道名稱,以獲取消息終點。 動態路由器有一個JMX入口點,它允許我即時切換端點。 如果消息端點設置為jmsChannelSender並且無法解析ActiveMQ url,則將導致整個系統崩潰。
我遇到的問題是,如果ActiveMQ URL無法訪問,我希望系統還原到使用簡單的多線程處理方法的其他消息通道。
這是下面的彈簧集成配置。 使用2.0.0.RELEASE版本
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx-2.0.xsd
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="dm-activitylogging-services.xml"/>
<bean name="decisionActivityLoggingAspect" class="com.idna.dm.aspects.logging.activity.DecisionActivityLogAspect"
factory-method="aspectOf">
<property name="activityLoggingGateway">
<ref bean="activityLoggingGateway" />
</property>
</bean>
<!-- New Activity Logging Services Reference dm-activity-logging -->
<!-- JMS Channel Adapter -->
<int:channel id="jmsSenderChannel" />
<bean id="destinationLocalQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg index="0" value="${activemq.queuename.activitylogging}" />
</bean>
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${activemq.url}" />
</bean>
<bean id="activityLogConverter" class="com.idna.dm.domain.activitylogging.jms.ActivityLogConverter" />
<jms:outbound-channel-adapter channel="jmsSenderChannel" destination="destinationLocalQueue" connection-factory="connectionFactory" message-converter="activityLogConverter"/>
<!-- In Process Adapter -->
<int:channel id="inProcessChannel" />
<int:outbound-channel-adapter channel="inProcessChannel" ref="inProcessAdapter" method="persistLog" />
<bean id="inProcessAdapter" class="com.idna.dm.logging.activity.impl.InProcessActivityLoggingImpl" >
<property name="activityLoggingService" >
<ref bean="activityLogging" />
</property>
</bean>
<int:channel id="asyncInProcessChannel" />
<int:outbound-channel-adapter channel="asyncInProcessChannel" ref="asyncInProcessAdapter" method="persistLog" />
<bean id="asyncInProcessAdapter" class="com.idna.dm.logging.activity.impl.AsyncInProcessActivityLoggingImpl" >
<property name="activityLoggingService">
<ref bean="activityLogging" />
</property>
</bean>
<!-- Custom channel for console output using the router -->
<!-- Console Channel
<int:channel id="consoleAdapterChannel" />
<int:outbound-channel-adapter channel="consoleAdapterChannel" ref="consoleAdapter" method="printToStdout" />
<bean id="consoleAdapter" class="com.idna.dm.logging.activity.util.StdoutTargetAdapter" />
-->
<!-- Log4j Channel -->
<int:channel id="loggingChannel" />
<int:logging-channel-adapter auto-startup="true" level="INFO" log-full-message="true" channel="loggingChannel" />
<!-- Router -->
<int:gateway id="activityLoggingGateway"
service-interface="com.idna.dm.logging.activity.logger.ActivityLoggingGateway" />
<int:channel id="activityLoggingChannel" />
<int:router input-channel="activityLoggingChannel" ref="dynamicRouter"
method="route" default-output-channel="asyncInProcessChannel"
ignore-channel-name-resolution-failures="true" />
<bean id="dynamicRouter" class="com.idna.dm.logging.activity.router.DynamicRouter">
<constructor-arg index="0" value="asyncInProcessChannel" />
</bean>
您可以使用failover
機制來實現:
<channel id="input">
<dispatcher load-balancer="none"/>
</channel>
<service-activator input-channel="input" order="1"/>
<service-activator input-channel="input" order="2"/>
在這種情況下,第一個<service-activator>
將始終被首先調用。 只有第二個失敗時,第二個才可以。
默認情況下, failover
為true
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.