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

The following examples show how to use org.apache.activemq.broker.BrokerService#start() . 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: NotificationMqttTaskModule.java    From hmdm-server with Apache License 2.0 6 votes vote down vote up
private boolean initBrokerService() {
    if (serverUri == null || serverUri.equals("")) {
        log.info("MQTT service not initialized (parameter mqtt.server.uri not set)");
        return false;
    }
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    try {
        brokerService.addConnector("mqtt://" + serverUri);
        brokerService.start();
        log.info("MQTT notification service started at " + serverUri);
    } catch (Exception e) {
        log.error("Failed to create MQTT broker service");
        e.printStackTrace();
        return false;
    }
    return true;
}
 
Example 2
Source File: Broker.java    From reactive-integration-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception{
  final String brokerName = args[0];
  final String connector = args[1];
  final BrokerService broker = new BrokerService() {
    { // We use an instance-initializer to set up our broker service.
      this.setUseJmx(false);
      this.setSchedulerSupport(false);
      this.setPersistent(false);
      this.setAdvisorySupport(false);
      this.setBrokerName(brokerName);
      final String connectTo = this.addConnector(connector).getPublishableConnectString();
      System.out.println("MQ running on: " + connectTo);
    }
  };
  broker.start(); // Once we've configured the broker, we'll start it.
  System.in.read();
  broker.stop();
  broker.waitUntilStopped();
}
 
Example 3
Source File: NonBlockingConsumerRedeliveryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
   broker = new BrokerService();
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setPersistent(false);
   broker.setUseJmx(false);
   broker.addConnector("tcp://0.0.0.0:0");
   broker.start();
   broker.waitUntilStarted();

   connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
   connectionFactory = new ActiveMQConnectionFactory(connectionUri);
   connectionFactory.setNonBlockingRedelivery(true);

   RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();
   policy.setInitialRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
   policy.setBackOffMultiplier(-1);
   policy.setRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
   policy.setMaximumRedeliveryDelay(-1);
   policy.setUseExponentialBackOff(false);
   policy.setMaximumRedeliveries(-1);
}
 
Example 4
Source File: QueuePurgeTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   setMaxTestTime(10 * 60 * 1000); // 10 mins
   setAutoFail(true);
   super.setUp();
   broker = new BrokerService();

   File testDataDir = new File("target/activemq-data/QueuePurgeTest");
   broker.setDataDirectoryFile(testDataDir);
   broker.setUseJmx(true);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.getSystemUsage().getMemoryUsage().setLimit(1024L * 1024 * 64);
   KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
   persistenceAdapter.setDirectory(new File(testDataDir, "kahadb"));
   broker.setPersistenceAdapter(persistenceAdapter);
   broker.addConnector("tcp://localhost:0");
   broker.start();
   factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri().toString());
   connection = factory.createConnection();
   connection.start();
}
 
Example 5
Source File: AMQ4889Test.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createBroker() throws Exception {
   brokerService = new BrokerService();
   brokerService.setPersistent(false);

   ArrayList<BrokerPlugin> plugins = new ArrayList<>();
   BrokerPlugin authenticationPlugin = configureAuthentication();
   plugins.add(authenticationPlugin);
   BrokerPlugin[] array = new BrokerPlugin[plugins.size()];
   brokerService.setPlugins(plugins.toArray(array));

   transportConnector = brokerService.addConnector(LOCAL_URI);
   proxyConnector = new ProxyConnector();
   proxyConnector.setName("proxy");
   proxyConnector.setBind(new URI(PROXY_URI));
   proxyConnector.setRemote(new URI(LOCAL_URI));
   brokerService.addProxyConnector(proxyConnector);

   brokerService.start();
   brokerService.waitUntilStarted();

   return brokerService;
}
 
Example 6
Source File: BrokerNetworkWithStuckMessagesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected BrokerService createSecondRemoteBroker() throws Exception {
   secondRemoteBroker = new BrokerService();
   secondRemoteBroker.setBrokerName("secondRemotehost");
   secondRemoteBroker.setUseJmx(false);
   secondRemoteBroker.setPersistenceAdapter(null);
   secondRemoteBroker.setPersistent(false);
   secondRemoteConnector = createSecondRemoteConnector();
   secondRemoteBroker.addConnector(secondRemoteConnector);
   configureBroker(secondRemoteBroker);
   secondRemoteBroker.start();
   secondRemoteBroker.waitUntilStarted();

   brokers.put(secondRemoteBroker.getBrokerName(), secondRemoteBroker);

   return secondRemoteBroker;
}
 
Example 7
Source File: MessageCompressionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   broker = new BrokerService();
   connectionUri = broker.addConnector(BROKER_URL).getPublishableConnectString();
   broker.start();
   queue = new ActiveMQQueue("TEST." + System.currentTimeMillis());
}
 
Example 8
Source File: TopicSubscriptionZeroPrefetchTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private BrokerService createBroker() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setBrokerName("localhost");
   broker.setUseJmx(false);
   broker.setDeleteAllMessagesOnStartup(true);
   broker.addConnector("vm://localhost");
   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example 9
Source File: LostScheduledMessagesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void startBroker() throws Exception {
   broker = new BrokerService();
   broker.setSchedulerSupport(true);
   broker.setPersistent(true);
   broker.setDeleteAllMessagesOnStartup(false);
   broker.setDataDirectory("target");
   broker.setSchedulerDirectoryFile(schedulerDirectory);
   broker.setDataDirectoryFile(messageDirectory);
   broker.setUseJmx(false);
   broker.addConnector("vm://localhost");
   broker.start();
}
 
Example 10
Source File: NIOSSLWindowSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
   System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
   System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
   System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);

   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true");
   broker.start();
   broker.waitUntilStarted();

   messageData = new byte[MESSAGE_SIZE];
   for (int i = 0; i < MESSAGE_SIZE; i++) {
      messageData[i] = (byte) (i & 0xff);
   }

   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
   connection = factory.createConnection();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   connection.start();
}
 
Example 11
Source File: SlowConsumerTopicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker(String url) throws Exception {
   Resource resource = new ClassPathResource("org/apache/activemq/perf/slowConsumerBroker.xml");
   System.err.println("CREATE BROKER FROM " + resource);
   BrokerFactoryBean factory = new BrokerFactoryBean(resource);
   factory.afterPropertiesSet();
   BrokerService broker = factory.getBroker();

   broker.start();
   return broker;
}
 
Example 12
Source File: DurableSubscriptionTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void createBroker() throws Exception {
   broker = new BrokerService();
   broker.setBrokerName("durable-broker");
   broker.setDeleteAllMessagesOnStartup(true);
   broker.setPersistenceAdapter(createPersistenceAdapter());
   broker.setPersistent(true);
   broker.start();
   broker.waitUntilStarted();

   connection = createConnection();
}
 
Example 13
Source File: DurableSubscriptionTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void createRestartedBroker() throws Exception {
   broker = new BrokerService();
   broker.setBrokerName("durable-broker");
   broker.setDeleteAllMessagesOnStartup(false);
   broker.setPersistenceAdapter(createPersistenceAdapter());
   broker.setPersistent(true);
   broker.start();
   broker.waitUntilStarted();

   connection = createConnection();
}
 
Example 14
Source File: PooledConnectionExampleTest.java    From amqp-10-jms-spring-boot with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    brokerService = new BrokerService();

    brokerService.addConnector("amqp://localhost:5672");
    brokerService.setPersistent(false);
    brokerService.getManagementContext().setCreateConnector(false);

    brokerService.start();
    brokerService.waitUntilStarted();
}
 
Example 15
Source File: ActiveMQTestBase.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
public BrokerService restartBroker(BrokerService brokerService) throws Exception {
  String name = brokerService.getBrokerName();
  Map<String, Integer> portMap = new HashMap<String, Integer>();
  for (TransportConnector connector : brokerService.getTransportConnectors()) {
    portMap.put(connector.getName(), connector.getPublishableConnectURI().getPort());
  }

  stopBroker(brokerService);
  BrokerService broker = createBroker(name, false, portMap);
  broker.start();
  broker.waitUntilStarted();
  return broker;
}
 
Example 16
Source File: DuplexNetworkMBeanTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
   BrokerService broker = createBroker();
   try {
      broker.start();
      assertEquals(1, countMbeans(broker, "connector", 30000));
      assertEquals(0, countMbeans(broker, "connectionName"));
      BrokerService networkedBroker = null;
      for (int i = 0; i < numRestarts; i++) {
         networkedBroker = createNetworkedBroker();
         try {
            networkedBroker.start();
            assertEquals(1, countMbeans(networkedBroker, "networkBridge", 2000));
            assertEquals(1, countMbeans(broker, "networkBridge", 2000));
            assertEquals(2, countMbeans(broker, "connectionName"));
         } finally {
            networkedBroker.stop();
            networkedBroker.waitUntilStopped();
         }
         assertEquals(0, countMbeans(networkedBroker, "stopped"));
         assertEquals(0, countMbeans(broker, "networkBridge"));
      }

      assertEquals(0, countMbeans(networkedBroker, "networkBridge"));
      assertEquals(0, countMbeans(networkedBroker, "connector"));
      assertEquals(0, countMbeans(networkedBroker, "connectionName"));
      assertEquals(1, countMbeans(broker, "connector"));
   } finally {
      broker.stop();
      broker.waitUntilStopped();
   }
}
 
Example 17
Source File: DispatchMultipleConsumersTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   broker = new BrokerService();
   broker.setPersistent(true);
   broker.setUseJmx(true);
   broker.deleteAllMessages();
   broker.addConnector("tcp://localhost:0");
   broker.start();
   broker.waitUntilStarted();
   dest = new ActiveMQQueue(destinationName);
   resetCounters();
   brokerURL = broker.getTransportConnectors().get(0).getPublishableConnectString();
}
 
Example 18
Source File: SimpleNetworkTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected BrokerService createProducerBroker(String uri) throws Exception {
   BrokerService answer = new BrokerService();
   configureProducerBroker(answer, uri);
   answer.start();
   return answer;
}
 
Example 19
Source File: TimeStampTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void test() throws Exception {
   BrokerService broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(true);
   broker.setPlugins(new BrokerPlugin[]{new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin()});
   TransportConnector tcpConnector = broker.addConnector("tcp://localhost:0");
   broker.addConnector("stomp://localhost:0");
   broker.start();

   // Create a ConnectionFactory
   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(tcpConnector.getConnectUri());

   // Create a Connection
   Connection connection = connectionFactory.createConnection();
   connection.start();

   // Create a Session
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   // Create the destination Queue
   Destination destination = session.createQueue("TEST.FOO");

   // Create a MessageProducer from the Session to the Topic or Queue
   MessageProducer producer = session.createProducer(destination);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   // Create a messages
   Message sentMessage = session.createMessage();

   // Tell the producer to send the message
   long beforeSend = System.currentTimeMillis();
   producer.send(sentMessage);
   long afterSend = System.currentTimeMillis();

   // assert message timestamp is in window
   assertTrue(beforeSend <= sentMessage.getJMSTimestamp() && sentMessage.getJMSTimestamp() <= afterSend);

   // Create a MessageConsumer from the Session to the Topic or Queue
   MessageConsumer consumer = session.createConsumer(destination);

   // Wait for a message
   Message receivedMessage = consumer.receive(1000);

   // assert we got the same message ID we sent
   assertEquals(sentMessage.getJMSMessageID(), receivedMessage.getJMSMessageID());

   // assert message timestamp is in window
   assertTrue("JMS Message Timestamp should be set during the send method: \n" + "        beforeSend = " + beforeSend + "\n" + "   getJMSTimestamp = " + receivedMessage.getJMSTimestamp() + "\n" + "         afterSend = " + afterSend + "\n", beforeSend <= receivedMessage.getJMSTimestamp() && receivedMessage.getJMSTimestamp() <= afterSend);

   // assert message timestamp is unchanged
   assertEquals("JMS Message Timestamp of received message should be the same as the sent message\n        ", sentMessage.getJMSTimestamp(), receivedMessage.getJMSTimestamp());

   // Clean up
   producer.close();
   consumer.close();
   session.close();
   connection.close();
}
 
Example 20
Source File: RequestReplyNoAdvisoryNetworkTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void startBrokers() throws Exception {
   for (BrokerService broker : brokers) {
      broker.start();
   }
}