private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    broker.setUseJmx(true);
    // Make topics "selectorAware"
    VirtualTopic virtualTopic = new VirtualTopic();
    virtualTopic.setSelectorAware(true);
    VirtualDestinationInterceptor interceptor = new VirtualDestinationInterceptor();
    interceptor.setVirtualDestinations(new VirtualDestination[] {virtualTopic});
    broker.setDestinationInterceptors(new DestinationInterceptor[] {interceptor});
    configurePersistenceAdapter(broker);

    SubQueueSelectorCacheBrokerPlugin selectorCacheBrokerPlugin =
        new SubQueueSelectorCacheBrokerPlugin();
    selectorCacheBrokerPlugin.setSingleSelectorPerDestination(true);
    File persisteFile = new File(PERSIST_SELECTOR_CACHE_FILE_BASEPATH + broker.getBrokerName());
    selectorCacheBrokerPlugin.setPersistFile(persisteFile);
    broker.setPlugins(new BrokerPlugin[] {selectorCacheBrokerPlugin});
    return broker;
  }
Ejemplo n.º 2
0
  /** Setup broker with VirtualTopic configured */
  private void setupBroker(String uri) {
    try {
      broker = BrokerFactory.createBroker(uri);

      VirtualDestinationInterceptor interceptor = new VirtualDestinationInterceptor();
      VirtualTopic virtualTopic = new VirtualTopic();
      virtualTopic.setName("VirtualOrders.>");
      virtualTopic.setSelectorAware(true);
      VirtualDestination[] virtualDestinations = {virtualTopic};
      interceptor.setVirtualDestinations(virtualDestinations);
      broker.setDestinationInterceptors(new DestinationInterceptor[] {interceptor});

      SubQueueSelectorCacheBrokerPlugin subQueueSelectorCacheBrokerPlugin =
          new SubQueueSelectorCacheBrokerPlugin();
      BrokerPlugin[] updatedPlugins = {subQueueSelectorCacheBrokerPlugin};
      broker.setPlugins(updatedPlugins);

      broker.start();
      broker.waitUntilStarted();
    } catch (Exception e) {
      LOG.error("Failed creating broker", e);
    }
  }