예제 #1
0
  @Before
  public void startBroker() throws Exception {
    brokerService = new BrokerService();
    TestSupport.setPersistenceAdapter(brokerService, persistenceAdapterChoice);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(false);

    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setUseConsumerPriority(
        false); // java.lang.IllegalArgumentException: Comparison method violates its general
                // contract!
    defaultEntry.setMaxAuditDepth(publisherThreadCount);
    defaultEntry.setEnableAudit(true);
    defaultEntry.setUseCache(useCache);
    defaultEntry.setMaxPageSize(1000);
    defaultEntry.setOptimizedDispatch(optimizeDispatch);
    defaultEntry.setMemoryLimit(destMemoryLimit);
    defaultEntry.setExpireMessagesPeriod(0);
    policyMap.setDefaultEntry(defaultEntry);
    brokerService.setDestinationPolicy(policyMap);

    brokerService.getSystemUsage().getMemoryUsage().setLimit(512 * 1024 * 1024);

    TransportConnector transportConnector = brokerService.addConnector("tcp://0.0.0.0:0");
    brokerService.start();
    activemqURL = transportConnector.getPublishableConnectString();
  }
  protected void configureBroker(BrokerService brokerService) throws Exception {
    setPersistentAdapter(brokerService);
    brokerService.setAdvisorySupport(false);

    PolicyMap map = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMemoryLimit(1024 * 3);
    defaultEntry.setCursorMemoryHighWaterMark(68);
    defaultEntry.setExpireMessagesPeriod(0);
    map.setDefaultEntry(defaultEntry);
    brokerService.setDestinationPolicy(map);
  }
  protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setPersistent(false);
    service.setUseJmx(false);

    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setUseConsumerPriority(true);
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);

    connector = service.addConnector("tcp://localhost:0");
    return service;
  }
  @Override
  protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();

    PolicyEntry policy = new PolicyEntry();
    policy.setDispatchPolicy(new SimpleDispatchPolicy());
    policy.setSubscriptionRecoveryPolicy(new FixedCountSubscriptionRecoveryPolicy());
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);

    broker.setDestinationPolicy(pMap);

    return broker;
  }
  private void doCreateBroker(boolean memoryLimit, int expireMessagesPeriod) throws Exception {
    broker = new BrokerService();
    broker.setBrokerName("localhost");
    broker.setUseJmx(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.addConnector("tcp://localhost:0");

    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setOptimizedDispatch(optimizedDispatch);
    defaultEntry.setExpireMessagesPeriod(expireMessagesPeriod);
    defaultEntry.setMaxExpirePageSize(800);

    defaultEntry.setPendingQueuePolicy(pendingQueuePolicy);

    if (memoryLimit) {
      // so memory is not consumed by DLQ turn if off
      defaultEntry.setDeadLetterStrategy(null);
      defaultEntry.setMemoryLimit(200 * 1000);
    }

    policyMap.setDefaultEntry(defaultEntry);

    broker.setDestinationPolicy(policyMap);
    broker.start();
    broker.waitUntilStarted();

    connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
  }
  // helper method to create a broker with slow consumer advisory turned on
  private BrokerService createBroker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("localhost");
    broker.setUseJmx(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.addConnector("vm://localhost");

    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setAdvisoryForSlowConsumers(true);

    policyMap.setDefaultEntry(defaultEntry);

    broker.setDestinationPolicy(policyMap);
    broker.start();
    broker.waitUntilStarted();
    return broker;
  }
  protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setDeleteAllMessagesOnStartup(true);

    service.setUseJmx(false);

    service.getSystemUsage().getStoreUsage().setLimit(200 * 1024);

    // allow destination to use 50% of store, leaving 50% for DLQ.
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setStoreUsageHighWaterMark(50);
    policyMap.put(queueDest, policy);
    policyMap.put(topicDest, policy);
    service.setDestinationPolicy(policyMap);

    connector = service.addConnector("tcp://localhost:0");
    return service;
  }
  @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;
  }
  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);
  }