What is the equivalent of destination-type from jms:listener-container in JavaConfig?

六眼飞鱼酱① 提交于 2019-12-08 01:38:41

问题


What is the equivalent of destination-type from jms:listener-container in JavaConfig?

I have checked in the API these two following classes without results.

  • DefaultMessageListenerContainer
  • MessageListenerAdapter

I am trying to create consumers for a topic, many tutorials in the web use destination-type="topic"

According with the 23.6 JMS Namespace Support section, there is the Table 23.2. Attributes of the JMS element table. Where for the destination-type attribute says:

The JMS destination type for this listener: queue, topic or durableTopic. The default is queue.

For the audience: consider the two following links if you are trying to do a migration from jms:listener-container and jms:listener for JavaConfig.

  • complete jms:listener migration to JavaConfig
  • How to add multiple JMS MessageListners in a single MessageListenerContainer for Spring Java Config

回答1:


When in doubt, look at the parser (in this case AbstractListenerContainerParser); that attribute doesn't map to a single property, it maps to pubSubDomain and subscriptionDurable...

    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:


Though this is a bit late, I would suggest to use the following approach for anyone who is still searching for the answer.

I have created a new Class DefaultMessageListenerContainerExtended which extends DefaultMessageListenerContainer and I have added one more method as setDestinationType. This does the trick in a nice and familiar way.

Following is the link to source code, which can be found on git:

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

Also to add, try to use spring version 4.2.5, as there are minor updates in that version (Had to dig a lot due to version issues as I was using 4.1.5 and Listener Containers did not had function to set "ReplyPubSubDomain" property).



来源:https://stackoverflow.com/questions/25212488/what-is-the-equivalent-of-destination-type-from-jmslistener-container-in-javaco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!