@Before public void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); brokerService.setPlugins(new BrokerPlugin[] { new BrokerPluginSupport() { @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { LOG.info("Remove Connection called for connection [{}] with error: {}", info.getConnectionId(), error); removeException.set(error); super.removeConnection(context, info, error); } }}); stealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=true").getPublishableConnectString(); unstealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=false").getPublishableConnectString(); brokerService.start(); }
/** * Disable the ActiveMQ Statistics Plugin. */ public void disableStatisticsPlugin() { if (isStatisticsPluginEnabled()) { BrokerPlugin[] currentPlugins = brokerService.getPlugins(); if (1 < currentPlugins.length) { BrokerPlugin[] newPlugins = new BrokerPlugin[currentPlugins.length - 1]; int i = 0; for (BrokerPlugin plugin : currentPlugins) { if (!(plugin instanceof StatisticsBrokerPlugin)) { newPlugins[i++] = plugin; } } brokerService.setPlugins(newPlugins); } else { brokerService.setPlugins(null); } } }
/** * Setup the broker so it will respond to statistics queries. * * @param broker to enable statistics for */ private void enableAMQStatistics(BrokerService brokerService) { // Start our stats plugin StatisticsBrokerPlugin statsPlugin = new StatisticsBrokerPlugin(); // Find what plugins are already present BrokerPlugin[] aPlugins = brokerService.getPlugins(); if (aPlugins == null) { aPlugins = new BrokerPlugin[] {}; } // Add stats to the list List<BrokerPlugin> lPlugins = new ArrayList<BrokerPlugin>(); lPlugins.addAll(Arrays.asList(aPlugins)); lPlugins.add(statsPlugin); // Setup the broker broker.setPlugins(lPlugins.toArray(aPlugins)); broker.setEnableStatistics(true); }
/** * Enable the ActiveMQ Statistics Plugin. */ public void enableStatisticsPlugin() { if (!isStatisticsPluginEnabled()) { BrokerPlugin[] newPlugins; BrokerPlugin[] currentPlugins = brokerService.getPlugins(); if (null != currentPlugins && 0 < currentPlugins.length) { newPlugins = new BrokerPlugin[currentPlugins.length + 1]; System.arraycopy(currentPlugins, 0, newPlugins, 0, currentPlugins.length); } else { newPlugins = new BrokerPlugin[1]; } newPlugins[newPlugins.length - 1] = new StatisticsBrokerPlugin(); brokerService.setPlugins(newPlugins); } }
protected BrokerService createBroker() throws Exception { BrokerService answer = new BrokerService(); BrokerPlugin[] plugins = new BrokerPlugin[1]; plugins[0] = new StatisticsBrokerPlugin(); answer.setPlugins(plugins); answer.setDeleteAllMessagesOnStartup(true); answer.addConnector("tcp://localhost:0"); answer.start(); return answer; }
broker = "broker".equals(uri.getScheme()) ? newDefaultBroker(uri) : BrokerFactory.createBroker(uri); if (plugins != null) { broker.setPlugins(plugins);
protected BrokerService createBroker(String name, boolean deleteMessagesOnStartup, Map<String, Integer> portMap) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setBrokerName(name); brokerService.setDeleteAllMessagesOnStartup(deleteMessagesOnStartup); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.setDataDirectory(DATA_PARENT_DIR + File.separator + "data" + File.separator + name); brokerService.setPersistent(false); brokerService.setSchedulerSupport(false); brokerService.setAdvisorySupport(false); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); BrokerPlugin authenticationPlugin = configureAuthentication(); if (authenticationPlugin != null) { plugins.add(authenticationPlugin); } if (!plugins.isEmpty()) { brokerService.setPlugins(plugins.toArray(new BrokerPlugin[0])); } addAdditionalConnectors(brokerService, portMap); return brokerService; }
private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception { brokerService = new BrokerService(); brokerService.setBrokerName(BROKER_NAME); brokerService.setUseJmx(false); brokerService.setPersistent(true); brokerService.setDataDirectoryFile(fileSystem.getFile(BROCKERS_LOCATION)); brokerService.setUseShutdownHook(false); brokerService.setSchedulerSupport(false); brokerService.setBrokerId(BROKER_ID); String[] uris = {BROCKER_URI}; brokerService.setTransportConnectorURIs(uris); ManagementContext managementContext = new ManagementContext(); managementContext.setCreateConnector(false); brokerService.setManagementContext(managementContext); brokerService.setPersistenceAdapter(persistenceAdapter); BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()}; brokerService.setPlugins(brokerPlugins); String[] transportConnectorsURIs = {BROCKER_URI}; brokerService.setTransportConnectorURIs(transportConnectorsURIs); brokerService.start(); LOGGER.info("Started embedded activeMq"); } }