0
votes

I'm looking for a way to conditionally set up jms:message-driven-channel-adapter in spring 3.0 & spring integration 2.2.

I would like to have an entry in a property file like: "create.message.driven.channel.adapter=true" for each environment and I would like spring to decide whether to set up the channel or not based solely on the entry from the property file.

Is there a way to accomplish this using only spring xml configuration and a property file?

1

1 Answers

1
votes

You can't do it exactly the way you describe. With Spring 3.1, you could do it with Spring Profiles...

<beans>
    ...

    <beans profile="foo">
       <jms:message-driven-adapter ... />
    </beans>
</beans>

Then run with ... -Dspring.profiles.active=foo.

You could do it with JavaConfig

@Bean
public Object foo() {
    // if property set, return an MDA, otherwise a String
}

Or, probably the easiest, so long as you don't explicitly start() the context, you could use

<jms:message-driven-adapter ... 
    auto-startup="${start.message.driven.channel.adapter}" />

In which case, the bean would be defined, but it just wouldn't be started so it wouldn't even open a JMS connection. You would also need a property placeholder configurer pointed at your properties file.

But, auto-startup only applies to starting on refresh(), an explicit context.start() will still start it.