protected void configureBroker(BrokerService answer) throws Exception {
    answer.setPersistent(false);
    answer.setMonitorConnectionSplits(true);
    final List<PolicyEntry> policyEntries = new ArrayList<PolicyEntry>();
    final PolicyEntry entry = new PolicyEntry();
    entry.setQueue(">");
    entry.setMemoryLimit(1024 * 1024 * 100); // Set to 1 MB
    entry.setOptimizedDispatch(true);
    entry.setProducerFlowControl(true);
    entry.setMaxPageSize(10);
    entry.setLazyDispatch(false);
    policyEntries.add(entry);

    final PolicyMap policyMap = new PolicyMap();
    policyMap.setPolicyEntries(policyEntries);
    answer.setDestinationPolicy(policyMap);
    super.configureBroker(answer);
  }
  @Before
  public void startBroker() throws Exception {
    broker = new BrokerService();
    broker.setDeleteAllMessagesOnStartup(true);

    // add the policy entries
    PolicyMap policyMap = new PolicyMap();
    List<PolicyEntry> entries = new ArrayList<PolicyEntry>();
    PolicyEntry pe = new PolicyEntry();
    pe.setExpireMessagesPeriod(0);

    pe.setQueuePrefetch(0); // make incremental dispatch to the consumers explicit
    pe.setStrictOrderDispatch(true); // force redeliveries back to the head of the queue

    pe.setQueue(">");
    entries.add(pe);
    policyMap.setPolicyEntries(entries);
    broker.setDestinationPolicy(policyMap);

    broker.addConnector("tcp://0.0.0.0:0");
    broker.start();
  }
  private BrokerService createBrokerService(
      final String brokerName, final String uri1, final String uri2) throws Exception {
    final BrokerService brokerService = new BrokerService();

    brokerService.setBrokerName(brokerName);
    brokerService.setPersistent(false);
    brokerService.setUseJmx(true);

    final SystemUsage memoryManager = new SystemUsage();
    // memoryManager.getMemoryUsage().setLimit(10);
    brokerService.setSystemUsage(memoryManager);

    final List<PolicyEntry> policyEntries = new ArrayList<>();

    final PolicyEntry entry = new PolicyEntry();
    entry.setQueue(">");
    // entry.setMemoryLimit(1);
    policyEntries.add(entry);

    final PolicyMap policyMap = new PolicyMap();
    policyMap.setPolicyEntries(policyEntries);
    brokerService.setDestinationPolicy(policyMap);

    final TransportConnector tConnector = new TransportConnector();
    tConnector.setUri(new URI(uri1));
    tConnector.setName(brokerName + ".transportConnector");
    brokerService.addConnector(tConnector);

    if (uri2 != null) {
      final NetworkConnector nc = new DiscoveryNetworkConnector(new URI("static:" + uri2));
      nc.setBridgeTempDestinations(true);
      nc.setBrokerName(brokerName);
      // nc.setPrefetchSize(1);
      brokerService.addNetworkConnector(nc);
    }

    return brokerService;
  }