ActiveMQ“经典”虚拟主题不适用于 python-stomp

问题描述 投票:0回答:1

我使用虚拟目标配置 ActiveMQ。

当我使用 python-stomp 测试配置时,虚拟主题设置对我来说永远不起作用。

我正在使用 Apache ActiveMQ 5.18.2,下面是我的

activemq.xml
:

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">

        <destinationPolicy>
            <policyMap>
                <policyEntries>
                    <policyEntry topic=">" >

                        <pendingMessageLimitStrategy>
                            <constantPendingMessageLimitStrategy limit="1000"/>
                        </pendingMessageLimitStrategy>
                    </policyEntry>
                </policyEntries>
            </policyMap>
        </destinationPolicy>

        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>

        <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage percentOfJvmHeap="70" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>
        
        <destinationInterceptors>
            <virtualDestinationInterceptor> 
                <virtualDestinations> 
                    <virtualTopic name=">" prefix="VirtualTopicConsumers.*." selectorAware="false"/>   
                    <compositeQueue name="MY.QUEUE">
                        <forwardTo>
                            <queue physicalName="FOO" /> 
                            <queue physicalName="BAR" />
                        </forwardTo>
                    </compositeQueue>
                </virtualDestinations>
            </virtualDestinationInterceptor>
        </destinationInterceptors>

        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>
    <import resource="jetty.xml"/>

</beans>

我使用 Python stomp 作为发布者和订阅者。

import time
import stomp

conn = stomp.Connection()
conn.connect('admin', 'admin', wait=True)
conn.send(body='123123', destination='VirtualTopic.test')
time.sleep(2)
conn.disconnect()
import time
import stomp

class MyListener(stomp.ConnectionListener):
    def on_error(self, message):
        print('received an error "%s"' % message.body)
    def on_message(self, frame):
        print('received a message "%s"' % frame)

conn = stomp.Connection()
conn.set_listener('', MyListener())

while True:
    conn.connect('admin', 'admin', wait=True)
    conn.subscribe(destination='VirtualTopicConsumers.A.VirtualTopic.test', id="1", ack='auto')
    time.sleep(3)
    conn.disconnect()

我启动订阅者,然后发布消息,但我的订阅者从未收到消息。

我该如何解决这个问题?

python activemq stomp
1个回答
0
投票

在 ActiveMQ 中,您需要在 STOMP 目标前面加上您想要的主题或队列类型,否则代理默认将其视为队列,因此您的代码可能会在发送时失败,因为代理会认为您正在发送到名为“VirtualTopic”的队列。 test”而不是您想要的主题。

  • 对于主题,前缀是 /topic/
  • 对于队列,前缀是 /queue/

请参阅文档了解更多信息

© www.soinside.com 2019 - 2024. All rights reserved.