【问题标题】:What is the equivalent of destination-type from jms:listener-container in JavaConfig?JavaConfig 中 jms:listener-container 的目标类型等价物是什么?
【发布时间】:2014-08-08 21:25:14
【问题描述】:

JavaConfig 中 destination-typejms:listener-container 的等价物是什么?

我在 API 中检查了以下两个类,但没有结果。

我正在尝试为一个主题创建消费者,网络上的许多教程使用destination-type="topic"

根据23.6 JMS Namespace Support 部分,有表23.2。 JMS 元素 表的属性。 destination-type 属性在哪里表示:

此侦听器的 JMS 目标类型:队列、主题或持久主题。默认是队列。

对于观众:如果您尝试从 jms:listener-containerjms:listener 迁移 JavaConfig,请考虑以下两个链接。

【问题讨论】:

    标签: spring spring-3 spring-jms spring-4


    【解决方案1】:

    如有疑问,请查看解析器(在本例中为 AbstractListenerContainerParser);该属性不映射到单个属性,它映射到 pubSubDomainsubscriptionDurable...

        String destinationType = ele.getAttribute(DESTINATION_TYPE_ATTRIBUTE);
        boolean pubSubDomain = false;
        boolean subscriptionDurable = false;
        if (DESTINATION_TYPE_DURABLE_TOPIC.equals(destinationType)) {
            pubSubDomain = true;
            subscriptionDurable = true;
        }
        else if (DESTINATION_TYPE_TOPIC.equals(destinationType)) {
            pubSubDomain = true;
        }
        else if ("".equals(destinationType) || DESTINATION_TYPE_QUEUE.equals(destinationType)) {
            // the default: queue
        }
        else {
            parserContext.getReaderContext().error("Invalid listener container 'destination-type': " +
                    "only \"queue\", \"topic\" and \"durableTopic\" supported.", ele);
        }
        configDef.getPropertyValues().add("pubSubDomain", pubSubDomain);
        configDef.getPropertyValues().add("subscriptionDurable", subscriptionDurable);
    

    【讨论】:

    【解决方案2】:

    虽然这有点晚了,但我建议任何仍在寻找答案的人使用以下方法。

    我创建了一个扩展 DefaultMessageListenerContainer 的新类 DefaultMessageListenerContainerExtended,并且我添加了一个方法作为 setDestinationType .这以一种很好且熟悉的方式来解决问题。

    以下是源码的链接,可以在git上找到:

    https://github.com/HVT7/spring-jms-set-destination-type/blob/master/DefaultMessageListenerContainerExtended.java

    另外补充一下,尝试使用spring版本4.2.5,因为那个版本有一些小的更新(由于版本问题不得不挖掘很多,因为我使用的是4.1.5和Listener容器没有设置“ReplyPubSubDomain”属性的功能)。

    【讨论】:

      猜你喜欢
      • 2019-03-29
      • 2014-06-24
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2018-01-11
      • 2011-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多