jms中的destination-type相当于什么:JavaConfig中的listener-container?

时间:2014-08-08 21:25:14

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

JavaConfig中destination-type的{​​{1}}相当于什么?

我已经在API中检查了以下两个没有结果的类。

我正在尝试为主题创建使用者,网络中的许多教程都使用jms:listener-container

根据23.6 JMS Namespace Support部分,有表23.2。 JMS元素表的属性。 目标类型属性的位置显示为:

  

此侦听器的JMS目标类型:queue,topic或durableTopic。默认为队列。

对于受众群体:如果您尝试从destination-type="topic"jms:listener-container迁移到JavaConfig,请考虑以下两个链接。

2 个答案:

答案 0 :(得分:2)

如有疑问,请查看解析器(在本例中为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);

答案 1 :(得分:-1)

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

我创建了一个新类 DefaultMessageListenerContainerExtended ,它扩展了 DefaultMessageListenerContainer ,我又增加了一个方法 setDestinationType 。这可以通过熟悉和熟悉的方式完成。

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

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

另外,请尝试使用spring版本 4.2.5 ,因为该版本中有少量更新(由于我使用4.1.5和Listener而导致版本问题需要大量挖掘容器没有设置“ReplyPubSubDomain”属性的功能。