// optional, reduce the usage limit so that spooling will occur faster
brokerService.getSystemUsage().getMemoryUsage().setLimit(10 * 1024 * 1024);
brokerService.getSystemUsage().getTempUsage().setLimit(numMessages * payLoadSize * 2);
PolicyMap policyMap = new PolicyMap();
List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
PolicyEntry policy = new PolicyEntry();
// NB: ensure queue cursor limit is below the default 70% usage that the destination will use
// if they are the same, the queue memory limit and flow control will kick in first
policy.setCursorMemoryHighWaterMark(20);
// on by default
//policy.setProducerFlowControl(true);
policy.setQueue(">");
// policy that will spool references to disk
policy.setPendingQueuePolicy(new FilePendingQueueMessageStoragePolicy());
entries.add(policy);
policyMap.setPolicyEntries(entries);
brokerService.setDestinationPolicy(policyMap);
brokerService.start();
}