How can I define a failover spring integration gateway? -


i'm new spring integration. have channel wired jms queue. have gateway defined has channel setup default-request-channel.

this basic configuration working flawlessly me. defined service-interface being injected bean , i'm able send message through interface , goes way through queue.

however, have additional requirement have failover queue defined if reason primary unreachable, attempt made send failover/secondary queue.

i not finding examples of type of configuration.

since channels wired jms queues, first thought create connection factory (pointing secondary jms server), create queue bean , channel , have gateway used if exception thrown first gateway invocation.

try {   primarygateway.sendmessage(message); } catch (exception e) {   secondarygateway.sendmessage(message); } 

however, began wonder if there built-in (under-the-covers) way spring integration configured autmatically try secondary queue if send primary fails.

also, had problem trying define secondary connection factory. i'm not sure how tell queue beans (or owning channels) connection factory use. if did not use default "connectionfactory" id, complaining.

here key portions of configuration single queue/channel/gateway defined:

<bean id="mqconnectionfactory" class="com.ibm.mq.jms.mqqueueconnectionfactory">   <property name="transporttype" value="1"/>   <property name="hostname" value="${lsm.primary.sch.outbound.host}"/>   <property name="port" value="${lsm.primary.sch.outbound.port}"/>   <property name="queuemanager" value="${lsm.primary.sch.outbound.manager}"/>   <property name="channel" value="${lsm.primary.sch.outbound.channel}"/> </bean>  <bean id="connectionfactory"   class="org.springframework.jms.connection.usercredentialsconnectionfactoryadapter">   <property name="targetconnectionfactory" ref="mqconnectionfactory" />   <property name="username" value="blah" />   <property name="password" value="blah" /> </bean>  <bean id="lsmscheduleactualoutboundqueue" class="com.ibm.mq.jms.mqqueue">   <property name="basequeuemanagername" value="${lsm.primary.sch.outbound.manager}"/>   <property name="basequeuename" value="${lsm.primary.sch.outbound.queue}"/> </bean>  <int:channel id="lsmscheduleactualoutboundchannel" />  <jms:outbound-channel-adapter id="jmsoutboundadapter"    channel="lsmscheduleactualoutboundchannel"    destination="lsmscheduleactualoutboundqueue" />   <int:gateway id="lsmscheduleactualoutboundgateway"    service-interface="com.myapp.service.lsmscheduleactualsgateway"   default-request-channel="lsmscheduleactualoutboundchannel"    default-request-timeout="1000" /> 

the outbound adapter won't fail on can wire 2 outbound adapters lsmscheduleactualoutboundchannel; default, framework round-robin requests can alter behavior configuring channel's <dispatcher/> load-balancer="none"; send message second adapter if first fails.

see reference manual 'direct channel' documentation , configuration more information

the channel adapter has connection-factory attribute; if not supplied defaults connectionfactory.


Comments