简体   繁体   中英

How to set a ConnectionFactory class to an Jms outboundAdapter? (within Spring Integration)

I'm using Spring Integration, and I'm trying (in the IntegrationFlow) to set an outboundAdapter with connectionFactory in Jms . Since I'm new to those classes I'm not being able to create anything that doesn't throw an error in that code snippet. How do I define the ConnectionFactory class for that to work?

private MessageChannel workflowExample() {
    return IntegrationFlows
            .from(requests())
            .transform(someTransformer())
            .handle(Jms.outboundAdapter(connectionFactory)
                   .destination("somewhere"))
            .get();
}

You need to understand what JMS client you are going to use. If that is ActiveMQ, then the ConnectionFactory could be like this:

ConnectionFactory amqFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false")

That's what we do for testing in the embedded mode.

If your JMS broker is managed by the JEE server, then you need to figure out a JNDI name for the ConnectionFactory object and use Spring JNDI support to obtain it.

If you deal with IBM MQ, then you need to use their JMS wrapper to be able to instantiate a ConnectionFactory properly. And so on. There is a client for Tibco JMS, some JMS wrapper for Rabbit MQ etc.

Anyway the ConnectionFactory instantiation is not Spring Integration responsibility. You really need to figure out what JMS client you use and follow its documentation how to create. Spring JMS support can help you with some boilerplate code and dependency management: https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/integration.html#remoting-jms

You also can take a look into profile support, so you can test your flows against embedded ActiveMQ locally and connect to external broker on production: https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/core.html#beans-definition-profiles

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM