Jim*_*moc 2 java messaging activemq-classic jms
我们在 ActiveMQ 中遇到了一个问题,我们有大量的消息没有脱离主题。主题设置为非持久性、非持久性。我们的 Activemq.xml 文件是
<beans>
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="false" persistent="false">
<!--
<persistenceAdapter>
<journaledJDBC journalLogFiles="5" dataDirectory="../data"/>
</persistenceAdapter>
-->
<transportConnectors>
<transportConnector uri="vm://localhost"/>
</transportConnectors>
</broker>
</beans>
Run Code Online (Sandbox Code Playgroud)
我们在 messages-config.xml 中的主题定义是
<destination id="traceChannel">
<properties>
<network>
<session-timeout>10</session-timeout>
</network>
<server>
<message-time-to-live>10000</message-time-to-live>
<durable>false</durable>
<durable-store-manager>flex.messaging.durability.FileStoreManager</durable-store-manager>
</server>
<jms>
<destination-type>Topic</destination-type>
<message-type>javax.jms.ObjectMessage</message-type>
<connection-factory>ConnectionFactory</connection-factory>
<destination-jndi-name>dynamicTopics/traceTopic</destination-jndi-name>
<delivery-mode>NON_PERSISTENT</delivery-mode>
<message-priority>DEFAULT_PRIORITY</message-priority>
<acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
<transacted-sessions>false</transacted-sessions>
<initial-context-environment>
<property>
<name>Context.INITIAL_CONTEXT_FACTORY</name>
<value>org.apache.activemq.jndi.ActiveMQInitialContextFactory</value>
</property>
<property>
<name>Context.PROVIDER_URL</name>
<value>tcp://localhost:61616</value>
</property>
</initial-context-environment>
</jms>
</properties>
<channels>
<channel ref="rtmps" />
</channels>
<adapter ref="trace" />
</destination>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,在任何时候都只有最后 10 条消息是关于主题的,因为让它在一夜之间运行会导致超过 150K 的关于该主题的消息,即使它应该只包含很少的数字。
据我所知,发送到没有订阅者的非持久主题的消息应该被删除。只有当前注册的消费者才能获得消息副本。
您如何检查该主题包含这 15 万条消息?通过 JMX?
不管您的非持久主题不应该缓存这 150K 条消息,您都可以使用代理策略限制每个消费者存储的消息量:
<broker>
...
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="10"/>
</pendingMessageLimitStrategy>
...
</broker>
Run Code Online (Sandbox Code Playgroud)