2015-10-16 169 views
1

我试图为我的邮件设置持久订阅者,以便即使在服务器重新启动后,它们也会在主题中持续存在。持久订阅ActiveMQ

但在配置过程中我得到有关XML错误:

这里是我的XML配置:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:int="http://www.springframework.org/schema/integration" 
     xmlns:int-jms="http://www.springframework.org/schema/integration/jms" 
     xmlns:oxm="http://www.springframework.org/schema/oxm" 
     xmlns:int-jme="http://www.springframework.org/schema/integration" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd 
       http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
       http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd 
       http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"> 


    <!-- Component scan to find all Spring components --> 
    <context:component-scan base-package="com.geekcap.springintegrationexample" /> 

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 
     <property name="order" value="1" /> 
     <property name="messageConverters"> 
      <list> 
       <!-- Default converters --> 
       <bean class="org.springframework.http.converter.StringHttpMessageConverter"/> 
       <bean class="org.springframework.http.converter.FormHttpMessageConverter"/> 
       <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" /> 
       <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/> 
       <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/> 
       <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" /> 
      </list> 
     </property> 
    </bean> 

    <!-- Define a channel to communicate out to a JMS Destination --> 
    <int:channel id="topicChannel"/> 

    <!-- Define the ActiveMQ connection factory --> 
    <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory"> 
     <property name="brokerURL" value="tcp://localhost:61616"/> 
    </bean> 

    <!-- 
     Define an adaptor that route topicChannel messages to the myTopic topic; the outbound-channel-adapter 
     automagically fines the configured connectionFactory bean (by naming convention 
     --> 
    <int-jms:outbound-channel-adapter channel="topicChannel" 
             destination-name="topic.myTopic" 
             pub-sub-domain="true" /> 

    <!-- Create a channel for a listener that will consume messages--> 
    <int:channel id="listenerChannel" /> 

    <int-jms:message-driven-channel-adapter id="messageDrivenAdapter" 
              channel="getPayloadChannel" 
              subscription-durable="true" 
              durable-subscription-name="myDurableSubscription" 
              destination-name="topic.myTopic" 
              pub-sub-domain="true" /> 

    <int:service-activator input-channel="listenerChannel" ref="messageListenerImpl" method="processMessage" /> 

    <int:channel id="getPayloadChannel" /> 

    <int:service-activator input-channel="getPayloadChannel" output-channel="listenerChannel" ref="retrievePayloadServiceImpl" method="getPayload" /> 

</beans> 

message-driven-channel-adapter下列属性给出了一个错误: enter image description here

它说:

在该行发现多个注释:

  • CVC-复type.3.2.2:属性 '订阅的耐用' 是不允许出现在元素 'INT-JMS:消息驱动-通道 - 适配器'。
  • cvc-complex-type.3.2.2:属性'durable-subscription-name'不允许出现在元素'int-jms:message-driven-channel- adapter'中。

但在更多的例子中,我可以看到下面的属性工作正常。

  • subscription-durable="true"

  • durable-subscription-name="myDurableSubscription"

那么可能是什么毛病我的配置。

编辑: Spring Integration的依赖关系的pom.xml

<!-- Spring Integration --> 
     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-core</artifactId> 
      <version>4.2.0.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-jms</artifactId> 
      <version>4.2.0.RELEASE</version> 
     </dependency> 

编辑:

请参见附件图片: enter image description here

也看到我日志这意味着目标方法当消息被客户端使用时,应该被调用。 enter image description here 请帮忙。

+0

检查DTD是否支持这些属性 – Saravana

+0

@Saravana感谢您的快速回复。但是我对XML操作并不熟悉,也不了解它。你能帮我吗? –

+0

@Vihar你能帮我解答吗? –

回答

3

您使用的是什么版本的Spring集成?在4年前的版本2.1.0.RELEASE中添加了对持久订阅的支持。

当前版本是4.2.0.RELEASE。

编辑

我忘了提及你需要持久订阅客户端ID。

你看过日志消息吗?这似乎很清楚...

14:12:39.557 WARN [jmsIn.container-1][org.springframework.jms.listener.DefaultMessageListenerContainer] Setup of JMS message listener invoker failed for destination 'topic://topic.demo' - trying to recover. Cause: You cannot create a durable subscriber without specifying a unique clientID on a Connection

添加一个clientId您连接工厂...

<property name="clientId" value="myClient"/> 
+0

我正在使用4.2.0.RELEASE只有 –

+0

我也想知道,因为春天文件本身已经提到这里http://docs.spring.io/spring-integration/reference/htmlsingle/#jms-message-driven-channel-适配器 –

+0

我已经通过添加pom.xml中使用的弹簧集成依赖关系更新了问题 –