【问题标题】:How to set a ConnectionFactory class to an Jms outboundAdapter? (within Spring Integration)如何将 ConnectionFactory 类设置为 Jms outboundAdapter? (在 Spring 集成中)
【发布时间】:2020-05-08 20:35:55
【问题描述】:

我正在使用 Spring Integration,我正在尝试(在 IntegrationFlow 中)在 Jms 中设置 outboundAdapterconnectionFactory。由于我是这些类的新手,因此我无法创建任何不会在该代码 sn-p 中引发错误的东西。如何定义 ConnectionFactory 类才能使其工作?

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

【问题讨论】:

  • >throw an error in that code snippet - 您需要显示异常及其堆栈跟踪。

标签: java spring jms spring-integration spring-jms


【解决方案1】:

您需要了解要使用的 JMS 客户端。 如果是 ActiveMQ,那么ConnectionFactory 可能是这样的:

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

这就是我们在嵌入式模式下进行测试时所做的。

如果您的 JMS 代理由 JEE 服务器管理,那么您需要为 ConnectionFactory 对象找出一个 JNDI 名称并使用 Spring JNDI 支持来获取它。

如果您使用 IBM MQ,那么您需要使用他们的 JMS 包装器才能正确地实例化 ConnectionFactory。等等。有一个 Tibco JMS 客户端,一些用于 Rabbit MQ 的 JMS 包装器等。

无论如何,ConnectionFactory 实例化不是 Spring Integration 的责任。你真的需要弄清楚你使用的是什么 JMS 客户端,并按照它的文档来创建。 Spring JMS 支持可以帮助您进行一些样板代码和依赖管理:https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/integration.html#remoting-jms

您还可以查看 profile 支持,以便您可以在本地针对嵌入式 ActiveMQ 测试您的流程并在生产环境中连接到外部代理:https://docs.spring.io/spring/docs/5.2.3.RELEASE/spring-framework-reference/core.html#beans-definition-profiles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2015-02-24
    • 2020-10-20
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 2012-06-14
    相关资源
    最近更新 更多