超出ActiveMQ内存限制 [英] ActiveMQ memory limit exceeded
问题描述
我尝试为以下行为配置ActiveMQ:当代理超出其内存限制时,它应将消息存储在持久性存储中。如果使用以下配置:
I try to configure ActiveMQ for the following behavior: when broker exceeds its memory limit, it should store message in persistence storage. If use the following configuration:
BrokerService broker = new BrokerService();
broker.setBrokerName("activemq");
KahaDBPersistenceAdapter persistence = new KahaDBPersistenceAdapter();
persistence.setDirectory(new File(config.getProperty("amq.persistenceDir", "amq")));
broker.setPersistenceAdapter(persistence);
broker.setVmConnectorURI(new URI("vm://activemq"));
broker.getSystemUsage().getMemoryUsage().setLimit(64 * 1024 * 1024L);
broker.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 1024 * 100L);
broker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 1024 * 100L);
PolicyEntry policyEntry = new PolicyEntry();
policyEntry.setCursorMemoryHighWaterMark(50);
policyEntry.setExpireMessagesPeriod(0L);
policyEntry.setPendingDurableSubscriberPolicy(new StorePendingDurableSubscriberMessageStoragePolicy());
policyEntry.setMemoryLimit(64 * 1024 * 1024L);
policyEntry.setProducerFlowControl(false);
broker.setDestinationPolicy(new PolicyMap());
broker.getDestinationPolicy().setDefaultEntry(policyEntry);
broker.setUseJmx(true);
broker.setPersistent(true);
broker.start();
但是,这不起作用。 ActiveMQ仍会消耗所需的内存来存储整个队列。我还尝试删除PolicyEntry,这导致代理在达到内存限制后停止生产者。在文档中找不到我做错的事情。
However, this does not work. ActiveMQ still consumes as much memory as needed to store the full queue. I also tried to remove PolicyEntry, that caused broker to stop producers after memory limit is reached. I could find nothing in documentation about what I am doing wrong.
推荐答案
我们使用 storeCursor 并按如下所示设置内存限制...这会将所有队列的内存量限制为100MB ...
we use a storeCursor and set the memory limit as follows...this will limit the amount of memory for all queues to 100MB...
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">" producerFlowControl="false" memoryLimit="100mb">
<pendingQueuePolicy>
<storeCursor/>
</pendingQueuePolicy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
请确保您设置了适用于政策的目的地 ...在我的XML示例中这是使用 queue =>
完成的,但是您的示例使用的是 new PolicyMap()
...尝试调用 policyEntry.setQueue(>)
而不是应用到所有队列或将特定的目的地添加到PolicyMap等。
make sure you set the "destinations" that your policy should apply against...in my XML examples this is done using queue=">"
, but your example is using a new PolicyMap()
...try calling policyEntry.setQueue(">")
instead to apply to all queues or add specific destinations to your PolicyMap, etc.
有关完整示例,请参见此测试...
see this test for a full example...
这篇关于超出ActiveMQ内存限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!