gpt4 book ai didi

java - 持久订阅 ActiveMQ

转载 作者:行者123 更新时间:2023-11-29 04:57:42 25 4
gpt4 key购买 nike

我正在尝试为我的消息设置持久订阅者,以便即使在服务器重新启动后它们也会在主题中持久存在。

但是在配置过程中我遇到了与 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-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-”中 适配器”。

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

  • subscription-durable="true"

  • durable-subscription-name="myDurableSubscription"

那我的配置可能有什么问题

编辑:POM.xml 中的 Spring Integration 依赖项

<!-- 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请帮忙。

最佳答案

您使用的是哪个版本的 Spring Integration? 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"/>

关于java - 持久订阅 ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33163613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com