Java Code Examples for org.apache.activemq.broker.BrokerService#setBrokerName()

The following examples show how to use org.apache.activemq.broker.BrokerService#setBrokerName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmxCreateNCTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testBridgeRegistration() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName(BROKER_NAME);
   broker.setUseJmx(true); // explicitly set this so no funny issues
   broker.start();
   broker.waitUntilStarted();

   // now create network connector over JMX
   ObjectName brokerObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME);
   BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext().newProxyInstance(brokerObjectName, BrokerViewMBean.class, true);

   assertNotNull("We could not retrieve the broker from JMX", proxy);

   // let's add the NC
   String connectoName = proxy.addNetworkConnector("static:(tcp://localhost:61617)");
   assertEquals("NC", connectoName);

   // Make sure we can retrieve the NC through JMX
   ObjectName networkConnectorObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME +
                                                             ",connector=networkConnectors,networkConnectorName=" + connectoName);
   NetworkConnectorViewMBean nc = (NetworkConnectorViewMBean) broker.getManagementContext().newProxyInstance(networkConnectorObjectName, NetworkConnectorViewMBean.class, true);

   assertNotNull(nc);
   assertEquals("NC", nc.getName());
}
 
Example 2
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void createRemoteBroker() throws Exception {
   remoteBroker = new BrokerService();
   remoteBroker.setBrokerName("REMOTE");
   remoteBroker.setUseJmx(true);
   remoteBroker.setSchedulePeriodForDestinationPurge(5000);
   ManagementContext managementContext = new ManagementContext();
   managementContext.setCreateConnector(false);
   remoteBroker.setManagementContext(managementContext);
   PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/remote");
   remoteBroker.setPersistenceAdapter(persistenceAdapter);
   List<NetworkConnector> networkConnectors = new ArrayList<>();
   DiscoveryNetworkConnector networkConnector = new DiscoveryNetworkConnector();
   networkConnector.setName("to local");
   // set maxInactivityDuration to 0, otherwise the broker restarts while you are in the debugger
   networkConnector.setUri(URI.create("static://(tcp://127.0.0.1:23539?wireFormat.maxInactivityDuration=0)"));
   networkConnector.setDuplex(true);
   //networkConnector.setNetworkTTL(5);
   //networkConnector.setDynamicOnly(true);
   networkConnector.setAlwaysSyncSend(true);
   networkConnector.setDecreaseNetworkConsumerPriority(false);
   networkConnector.setPrefetchSize(1);
   networkConnector.setCheckDuplicateMessagesOnDuplex(true);
   networkConnectors.add(networkConnector);
   remoteBroker.setNetworkConnectors(networkConnectors);
}
 
Example 3
Source File: TestBroker.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public TestBroker build() throws Exception {
    if (this.connectors.isEmpty()) {
        this.connectors.add(DEFAULT_BROKER_URL);
    }
    BrokerService brokerService = new BrokerService();
    brokerService.setBrokerName(this.brokerName);
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    Map<String, ActiveMQConnectionFactory> connectionFactories = new HashMap<String, ActiveMQConnectionFactory>();
    for (String bindAddress : this.connectors) {
        TransportConnector connector = brokerService.addConnector(bindAddress);
        connectionFactories.put(bindAddress, new ActiveMQConnectionFactory(connector.getConnectUri()));
    }
    for (String discoveryAddress : this.networkConnectors) {
        brokerService.addNetworkConnector(discoveryAddress);
    }
    return new TestBroker(this.brokerName, brokerService, connectionFactories);
}
 
Example 4
Source File: TopicSubscriptionSlowConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: QueueOptimizedDispatchExceptionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

   // Setup and start the broker
   broker = new BrokerService();
   broker.setBrokerName(brokerName);
   broker.setPersistent(false);
   broker.setSchedulerSupport(false);
   broker.setUseJmx(false);
   broker.setUseShutdownHook(false);
   broker.addConnector(brokerUrl);

   // Start the broker
   broker.start();
   broker.waitUntilStarted();
}
 
Example 6
Source File: EmbeddedJMSBrokerLauncher.java    From cxf with Apache License 2.0 6 votes vote down vote up
public final void run() {
    try {
        broker = new BrokerService();
        broker.setPersistent(false);
        broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
        broker.setTmpDataDirectory(new File("./target"));
        broker.setUseJmx(false);
        if (brokerName != null) {
            broker.setBrokerName(brokerName);
        }
        broker.addConnector(brokerUrl1);
        broker.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: JMXRemoveQueueThenSendIgnoredTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
   brokerService = new BrokerService();
   brokerService.setBrokerName("dev");
   brokerService.setPersistent(false);
   brokerService.setUseJmx(true);
   brokerService.addConnector("tcp://localhost:0");
   brokerService.start();

   final String brokerUri = brokerService.getTransportConnectors().get(0).getPublishableConnectString();

   ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerUri);
   connection = activeMQConnectionFactory.createQueueConnection();
   session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE/*SESSION_TRANSACTED*/);
   queue = session.createQueue("myqueue");
   producer = session.createProducer(queue);
   producer.setDeliveryMode(DeliveryMode.PERSISTENT);

   connection.start();
}
 
Example 8
Source File: FailoverStaticNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(String scheme,
                                     String listenPort,
                                     String[] networkToPorts,
                                     HashMap<String, String> networkProps) throws Exception {
   BrokerService broker = new BrokerService();
   broker.getManagementContext().setCreateConnector(false);
   broker.setSslContext(sslContext);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setBrokerName("Broker_" + listenPort);
   // lazy init listener on broker start
   TransportConnector transportConnector = new TransportConnector();
   transportConnector.setUri(new URI(scheme + "://localhost:" + listenPort));
   List<TransportConnector> transportConnectors = new ArrayList<>();
   transportConnectors.add(transportConnector);
   broker.setTransportConnectors(transportConnectors);
   if (networkToPorts != null && networkToPorts.length > 0) {
      StringBuilder builder = new StringBuilder("static:(failover:(" + scheme + "://localhost:");
      builder.append(networkToPorts[0]);
      for (int i = 1; i < networkToPorts.length; i++) {
         builder.append("," + scheme + "://localhost:" + networkToPorts[i]);
      }
      // limit the reconnects in case of initial random connection to slave
      // leaving randomize on verifies that this config is picked up
      builder.append(")?maxReconnectAttempts=0)?useExponentialBackOff=false");
      NetworkConnector nc = broker.addNetworkConnector(builder.toString());
      if (networkProps != null) {
         IntrospectionSupport.setProperties(nc, networkProps);
      }
   }
   return broker;
}
 
Example 9
Source File: JDBCQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMaster() throws Exception {
   master = new BrokerService();
   master.setBrokerName("master");
   master.addConnector(MASTER_URL);
   master.setUseJmx(false);
   master.setPersistent(true);
   master.setDeleteAllMessagesOnStartup(true);
   JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
   persistenceAdapter.setDataSource(getExistingDataSource());
   configureJdbcPersistenceAdapter(persistenceAdapter);
   master.setPersistenceAdapter(persistenceAdapter);
   configureBroker(master);
   master.start();
}
 
Example 10
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(String brokerName) throws Exception {
   BrokerService answer = new BrokerService();
   answer.setPersistent(false);
   answer.setUseJmx(false);
   answer.setBrokerName(brokerName);
   answer.setUseShutdownHook(false);
   return answer;
}
 
Example 11
Source File: JMSAppenderTest.java    From servicemix with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBroker() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.setBrokerName("test.broker");
    broker.start();
}
 
Example 12
Source File: JMSTestBase.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * Start JMS broker from the Testcase.
 *
 * @throws Exception
 */
private void startJMSService() throws Exception
{
  broker = new BrokerService();
  String brokerName = "ActiveMQOutputOperator-broker";
  broker.setBrokerName(brokerName);
  broker.getPersistenceAdapter().setDirectory(new File("target/activemq-data/" + broker.getBrokerName() + '/' + org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter.class.getSimpleName()).getAbsoluteFile());
  broker.addConnector("tcp://localhost:61617?broker.persistent=false");
  broker.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 1024);  // 1GB
  broker.getSystemUsage().getTempUsage().setLimit(100 * 1024 * 1024);    // 100MB
  broker.setDeleteAllMessagesOnStartup(true);
  broker.start();
}
 
Example 13
Source File: mKahaDbQueueMasterSlaveTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createSlave() throws Exception {
   // use a separate thread as the slave will block waiting for
   // the exclusive db lock
   Thread t = new Thread() {
      @Override
      public void run() {
         try {
            BrokerService broker = new BrokerService();
            broker.setBrokerName("slave");
            TransportConnector connector = new TransportConnector();
            connector.setUri(new URI(SLAVE_URL));
            broker.addConnector(connector);
            // no need for broker.setMasterConnectorURI(masterConnectorURI)
            // as the db lock provides the slave/master initialisation
            broker.setUseJmx(false);
            broker.setPersistent(true);

            MultiKahaDBPersistenceAdapter mKahaDB = new MultiKahaDBPersistenceAdapter();
            List<FilteredKahaDBPersistenceAdapter> adapters = new LinkedList<>();
            FilteredKahaDBPersistenceAdapter defaultEntry = new FilteredKahaDBPersistenceAdapter();
            defaultEntry.setPersistenceAdapter(new KahaDBPersistenceAdapter());
            defaultEntry.setPerDestination(true);
            adapters.add(defaultEntry);

            mKahaDB.setFilteredPersistenceAdapters(adapters);
            broker.setPersistenceAdapter(mKahaDB);
            broker.start();
            slave.set(broker);
            slaveStarted.countDown();
         } catch (IllegalStateException expectedOnShutdown) {
         } catch (Exception e) {
            fail("failed to start slave broker, reason:" + e);
         }
      }
   };
   t.start();
}
 
Example 14
Source File: QueueBridgeStandaloneReconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createSecondBroker() throws Exception {

      BrokerService broker = new BrokerService();
      broker.setBrokerName("broker2");
      broker.setPersistent(false);
      broker.setUseJmx(false);
      broker.addConnector("tcp://localhost:61617");

      return broker;
   }
 
Example 15
Source File: JmsMultipleBrokersTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker(String brokerName) throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName(brokerName);
   brokers.put(brokerName, new BrokerItem(broker));

   return broker;
}
 
Example 16
Source File: NetworkBrokerDetachTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName(BROKER_NAME);
   configureBroker(broker);
   broker.addConnector("tcp://localhost:61617");
   NetworkConnector networkConnector = broker.addNetworkConnector("static:(tcp://localhost:62617?wireFormat.maxInactivityDuration=500)?useExponentialBackOff=false");
   configureNetworkConnector(networkConnector);
   return broker;
}
 
Example 17
Source File: QueueMasterSlaveSingleUrlTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMaster() throws Exception {
   master = new BrokerService();
   master.setBrokerName("shared-master");
   configureSharedPersistenceAdapter(master);
   master.addConnector(brokerUrl);
   master.start();
}
 
Example 18
Source File: ExpiredMessagesWithNoConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 19
Source File: TraceBrokerPathPluginTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   TraceBrokerPathPlugin tbppA = new TraceBrokerPathPlugin();
   tbppA.setStampProperty(traceProperty);

   TraceBrokerPathPlugin tbppB = new TraceBrokerPathPlugin();
   tbppB.setStampProperty(traceProperty);

   brokerA = new BrokerService();
   brokerA.setBrokerName("brokerA");
   brokerA.setPersistent(false);
   brokerA.setUseJmx(true);
   brokerA.setPlugins(new BrokerPlugin[]{tbppA});
   tcpConnectorA = brokerA.addConnector("tcp://localhost:0");

   brokerB = new BrokerService();
   brokerB.setBrokerName("brokerB");
   brokerB.setPersistent(false);
   brokerB.setUseJmx(true);
   brokerB.setPlugins(new BrokerPlugin[]{tbppB});
   tcpConnectorB = brokerB.addConnector("tcp://localhost:0");

   brokerA.addNetworkConnector("static:(" + tcpConnectorB.getConnectUri().toString() + ")");

   brokerB.start();
   brokerB.waitUntilStarted();
   brokerA.start();
   brokerA.waitUntilStarted();

   // Initialise connection to A and MessageProducer
   connectionA = new ActiveMQConnectionFactory(tcpConnectorA.getConnectUri()).createConnection();
   connectionA.start();
   sessionA = connectionA.createSession(false, Session.AUTO_ACKNOWLEDGE);
   producer = sessionA.createProducer(sessionA.createQueue(queue));
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   // Initialise connection to B and MessageConsumer
   connectionB = new ActiveMQConnectionFactory(tcpConnectorB.getConnectUri()).createConnection();
   connectionB.start();
   sessionB = connectionB.createSession(false, Session.AUTO_ACKNOWLEDGE);
   consumer = sessionB.createConsumer(sessionB.createQueue(queue));

}
 
Example 20
Source File: PublishJMSIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * This test validates the connection resources are closed if the publisher is marked as invalid.
 * </p>
 * <p>
 * This tests validates the proper resources handling for TCP connections using ActiveMQ (the bug was discovered against ActiveMQ 5.x). In this test, using some ActiveMQ's classes is possible to
 * verify if an opened socket is closed. See <a href="NIFI-7034">https://issues.apache.org/jira/browse/NIFI-7034</a>.
 * </p>
 * @throws Exception any error related to the broker.
 */
@Test(timeout = 10000)
public void validateNIFI7034() throws Exception {
    class PublishJmsForNifi7034 extends PublishJMS {
        @Override
        protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession, JMSPublisher publisher) throws ProcessException {
            super.rendezvousWithJms(context, processSession, publisher);
            publisher.setValid(false);
        }
    }
    BrokerService broker = new BrokerService();
    try {
        broker.setPersistent(false);
        broker.setBrokerName("nifi7034publisher");
        TransportConnector connector = broker.addConnector("tcp://127.0.0.1:0");
        int port = connector.getServer().getSocketAddress().getPort();
        broker.start();

        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("validateNIFI7034://127.0.0.1:" + port);
        final String destinationName = "nifi7034";
        final AtomicReference<TcpTransport> tcpTransport = new AtomicReference<TcpTransport>();
        TcpTransportFactory.registerTransportFactory("validateNIFI7034", new TcpTransportFactory() {
            @Override
            protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFactory, URI location, URI localLocation) throws UnknownHostException, IOException {
                TcpTransport transport = super.createTcpTransport(wf, socketFactory, location, localLocation);
                tcpTransport.set(transport);
                return transport;
            }
        });

        TestRunner runner = TestRunners.newTestRunner(new PublishJmsForNifi7034());
        JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
        when(cs.getIdentifier()).thenReturn("cfProvider");
        when(cs.getConnectionFactory()).thenReturn(cf);
        runner.addControllerService("cfProvider", cs);
        runner.enableControllerService(cs);

        runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
        runner.setProperty(PublishJMS.DESTINATION, destinationName);
        runner.setProperty(PublishJMS.DESTINATION_TYPE, PublishJMS.TOPIC);

        runner.enqueue("hi".getBytes());
        runner.run();
        assertFalse("It is expected transport be closed. ", tcpTransport.get().isConnected());
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}