本文介绍了持久订阅ActiveMQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为消息放置持久订阅者,以使它们即使在服务器重新启动后也能保留在主题中.

I am trying to put in place durable subscriber for my messages so that they will get persist in topic even after server restart.

但是在配置过程中,我遇到了与xml相关的错误:

But during configuration I am getting error related to 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中,以下属性给出错误:

But in message-driven-channel-adapter following attributes gives an error:

它说:

在此行找到多个注释:

  • cvc-complex-type.3.2.2:不允许属性"subscription-durable"出现在元素"int-jms:message-driven-channel-"中 适配器".
  • cvc-complex-type.3.2.2:不允许属性"durable-subscription-name"出现在元素"int-jms:message-driven-channel-"中 适配器".
  • cvc-complex-type.3.2.2: Attribute 'subscription-durable' is not allowed to appear in element 'int-jms:message-driven-channel- adapter'.
  • cvc-complex-type.3.2.2: Attribute 'durable-subscription-name' is not allowed to appear in element 'int-jms:message-driven-channel- adapter'.

但是在更多示例中,我可以看到以下属性正常工作.

But in lot more examples I can see below attributes are working fine.

  • subscription-durable="true"

durable-subscription-name="myDurableSubscription"

那我的配置可能出了什么问题.

Then what may be wrong with my configuration.

POM.xml中的Spring Integration依赖项

Spring Integration dependencies in 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>

请参阅所附图片:

也请参阅我的日志,该日志表明已调用目标方法,该方法应该在客户端使用消息时发生.请帮忙.

Also see my log which signifies that target method has been invoked which is supposed to be happened when message has been consumed by client.Please help.

推荐答案

您正在使用哪个版本的Spring Integration?超过4年前,在2.1.0.RELEASE版本中添加了对持久订阅的支持.

What version of Spring Integration are you using? Support for durable subscriptions was added in version 2.1.0.RELEASE, over 4 years ago.

当前版本是4.2.0.RELEASE.

The current version is 4.2.0.RELEASE.

编辑:

我忘了提到您需要长期订阅的客户端ID.

I forgot to mention you need a client id for durable subscriptions.

您是否查看了日志消息?这似乎很清楚...

Did you look at the log messages? This seems pretty clear...

将clientId添加到您的连接工厂...

Add a clientId to your connection factory...

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

这篇关于持久订阅ActiveMQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 17:44