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

The following examples show how to use org.apache.activemq.broker.BrokerService#stop() . 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: ConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testJournalConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testJournalConfig/journal");
   recursiveDelete(journalFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "journal-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerJournalConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a journal persistence adapter", adapter instanceof JournalPersistenceAdapter);
      assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists());

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example 2
Source File: ActiveMQResourceAdapter.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void stopImpl() throws Exception {
    super.stop();
    final Collection<BrokerService> brokers = ActiveMQFactory.getBrokers();
    final Iterator<BrokerService> it = brokers.iterator();
    while (it.hasNext()) {
        final BrokerService bs = it.next();
        try {
            bs.stop();
            bs.waitUntilStopped();
        } catch (final Throwable t) {
            //Ignore
        }
        it.remove();
    }
    stopScheduler();
    Logger.getInstance(LogCategory.OPENEJB_STARTUP, ActiveMQResourceAdapter.class).getChildLogger("service").info("Stopped ActiveMQ broker");
}
 
Example 3
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testXmlConfigHelper() throws Exception {
   BrokerService broker;

   broker = createBroker(new FileSystemResource(CONF_ROOT + "memory-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerMemoryConfigTest", broker.getBrokerName());
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }

   broker = createBroker("org/apache/activemq/config/config.xml");
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerXmlConfigHelper", broker.getBrokerName());
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example 4
Source File: NetworkLoopBackTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoopbackOnDifferentUrlScheme() throws Exception {
   final BrokerService brokerServce = new BrokerService();
   brokerServce.setPersistent(false);

   TransportConnector transportConnector = brokerServce.addConnector("nio://0.0.0.0:0");
   // connection filter is bypassed when scheme is different
   final NetworkConnector networkConnector = brokerServce.addNetworkConnector("static:(tcp://" + transportConnector.getConnectUri().getHost() + ":" + transportConnector.getConnectUri().getPort() + ")");

   brokerServce.start();
   brokerServce.waitUntilStarted();

   try {
      Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            return 1 == networkConnector.bridges.size();
         }
      });

      final DemandForwardingBridgeSupport loopbackBridge = (DemandForwardingBridgeSupport) networkConnector.bridges.values().iterator().next();
      assertTrue("nc started", networkConnector.isStarted());

      assertTrue("It should get disposed", Wait.waitFor(new Wait.Condition() {
         @Override
         public boolean isSatisified() throws Exception {
            return loopbackBridge.getRemoteBroker().isDisposed();
         }
      }));

      assertEquals("No peer brokers", 0, brokerServce.getBroker().getPeerBrokerInfos().length);

   } finally {
      brokerServce.stop();
   }
}
 
Example 5
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMemoryConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig");
   recursiveDelete(journalFile);

   File derbyFile = new File(DERBY_ROOT + "testMemoryConfig");
   recursiveDelete(derbyFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "memory-example.xml"));

   try {
      assertEquals("Broker Config Error (brokerName)", "brokerMemoryConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a memory persistence adapter", adapter instanceof MemoryPersistenceAdapter);
      assertTrue("Should have not created a derby directory at " + derbyFile.getAbsolutePath(), !derbyFile.exists());
      assertTrue("Should have not created a journal directory at " + journalFile.getAbsolutePath(), !journalFile.exists());

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example 6
Source File: BrokerPropertiesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testPropertiesFile() throws Exception {
   BrokerService broker = BrokerFactory.createBroker("properties:org/apache/activemq/config/broker.properties");

   LOG.info("Created broker: " + broker);
   assertNotNull(broker);

   assertEquals("isUseJmx()", false, broker.isUseJmx());
   assertEquals("isPersistent()", false, broker.isPersistent());
   assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
   broker.stop();
}
 
Example 7
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void destroyBrokerCluster() throws JMSException, Exception {
   for (BrokerService b : brokers.values()) {
      try {
         b.stop();
         b.waitUntilStopped();
      } catch (Exception e) {
         // Keep on going, we want to try and stop them all.
         logger.info("Error while stopping broker[" + b.getBrokerName() + "] continuing...");
      }
   }
   brokers.clear();
}
 
Example 8
Source File: ActiveMQ5FactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void checkManagementContext() throws Exception {
    final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + getNextAvailablePort() + ")?" +
            "useJmx=true");

    BrokerService bs = null;
    try {
        bs = new ActiveMQ5Factory().createBroker(brokerURI);
        assertFalse(bs.getManagementContext().isCreateConnector());
    } finally {
        if (bs != null) {
            bs.stop();
        }
    }
}
 
Example 9
Source File: ActiveMQ5FactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Test
public void setPlugins() throws Exception {
    final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + getNextAvailablePort() + ")?" +
            "amq.plugins=jaas&" +
            "jaas.class=" + JaasAuthenticationPlugin.class.getName() + "&" +
            "jaas.discoverLoginConfig=false");
    final BrokerService bs = new ActiveMQ5Factory().createBroker(brokerURI);
    bs.stop();
    ActiveMQ5Factory.brokers.remove(brokerURI);
    assertNotNull(bs.getPlugins());
    assertEquals(1, bs.getPlugins().length);
    assertTrue(JaasAuthenticationPlugin.class.isInstance(bs.getPlugins()[0]));
    assertFalse(JaasAuthenticationPlugin.class.cast(bs.getPlugins()[0]).isDiscoverLoginConfig()); // default is true
}
 
Example 10
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 11
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception {
   broker = new BrokerService();
   broker.setPersistent(false);
   broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
   broker.start();

   // This should create the connection.
   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61610/localhost:51610");
   connection = (ActiveMQConnection) cf.createConnection();
   assertNotNull(connection);

   connection.close();

   broker.stop();
}
 
Example 12
Source File: ConsumeJMSIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates <a href="https://issues.apache.org/jira/browse/NIFI-6915">NIFI-6915</a>.
 * <p>
 * The test consists on:
 * <ul>
 * <li>Start a durable non shared consumer <tt>C1</tt> with client id <tt>client1</tt> subscribed to topic <tt>T</tt>.</li>
 * <li>Stop <tt>C1</tt>.</li>
 * <li>Publish a message <tt>M1</tt> to topic <tt>T</tt>.</li>
 * <li>Start <tt>C1</tt>.</li>
 * </ul>
 * It is expected <tt>C1</tt> receives message <tt>M1</tt>.
 * </p>
 * @throws Exception
 *             unexpected
 */
@Test(timeout = 10000)
public void validateNifi6915() throws Exception {
    BrokerService broker = new BrokerService();
    try {
        broker.setPersistent(false);
        broker.setBrokerName("broker1");
        broker.start();
        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://broker1");
        final String destinationName = "validateNifi6915";

        TestRunner c1Consumer = createNonSharedDurableConsumer(cf, destinationName);
        // 1. Start a durable non shared consumer C1 with client id client1 subscribed to topic T.
        boolean stopConsumer = true;
        c1Consumer.run(1, stopConsumer);
        List<MockFlowFile> flowFiles = c1Consumer.getFlowFilesForRelationship(ConsumeJMS.REL_SUCCESS);
        assertTrue("Expected no messages", flowFiles.isEmpty());
        // 2. Publish a message M1 to topic T.
        publishAMessage(cf, destinationName, "Hi buddy!!");
        // 3. Start C1.
        c1Consumer.run(1, true);
        flowFiles = c1Consumer.getFlowFilesForRelationship(ConsumeJMS.REL_SUCCESS);
        assertEquals(1, flowFiles.size());

        // It is expected C1 receives message M1.
        final MockFlowFile successFF = flowFiles.get(0);
        assertNotNull(successFF);
        successFF.assertAttributeExists(JmsHeaders.DESTINATION);
        successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
        successFF.assertContentEquals("Hi buddy!!".getBytes());
        assertEquals(destinationName, successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME));
    } catch (Exception e) {
        throw e;
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}
 
Example 13
Source File: JDBCConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJdbcConfig() throws Exception {
   File journalFile = new File(JOURNAL_ROOT + "testJDBCConfig/journal");
   recursiveDelete(journalFile);

   File derbyFile = new File(DERBY_ROOT + "testJDBCConfig/derbydb"); // Default
   recursiveDelete(derbyFile);

   BrokerService broker;
   broker = createBroker(new FileSystemResource(CONF_ROOT + "jdbc-example.xml"));
   try {
      assertEquals("Broker Config Error (brokerName)", "brokerJdbcConfigTest", broker.getBrokerName());

      PersistenceAdapter adapter = broker.getPersistenceAdapter();

      assertTrue("Should have created a jdbc persistence adapter", adapter instanceof JDBCPersistenceAdapter);
      assertEquals("JDBC Adapter Config Error (cleanupPeriod)", 60000, ((JDBCPersistenceAdapter) adapter).getCleanupPeriod());
      assertTrue("Should have created an EmbeddedDataSource", ((JDBCPersistenceAdapter) adapter).getDataSource() instanceof EmbeddedDataSource);
      assertTrue("Should have created a DefaultWireFormat", ((JDBCPersistenceAdapter) adapter).getWireFormat() instanceof ObjectStreamWireFormat);

      LOG.info("Success");
   } finally {
      if (broker != null) {
         broker.stop();
      }
   }
}
 
Example 14
Source File: RequestReplyNoAdvisoryNetworkTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
   for (BrokerService broker : brokers) {
      broker.stop();
   }
   brokers.clear();
}
 
Example 15
Source File: PythonAgentIntegrationTest.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
protected void stopActiveMQInstance(String brokerName) {
    if (this.messageBrokers.containsKey(brokerName)) {
        log.debug("Stopping broker service [" + brokerName + "]");
        BrokerService broker = this.messageBrokers.get(brokerName);
        try {
            broker.stop();
        } catch (Exception ignore) {
        }
    }
}
 
Example 16
Source File: ActiveMQTestBase.java    From vertx-proton with Apache License 2.0 4 votes vote down vote up
public void stopBroker(BrokerService broker) throws Exception {
  if (broker != null) {
    broker.stop();
    broker.waitUntilStopped();
  }
}
 
Example 17
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected void stopBroker(String name) throws Exception {
   BrokerService broker = brokers.remove(name);
   broker.stop();
   broker.waitUntilStopped();
}
 
Example 18
Source File: JmsProtocolTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
  public void testHessianProtocol() throws URISyntaxException, Exception {

ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();

//Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
//Invoker<DemoService> invokerp = protocol.refer(DemoService.class, URL.valueOf("jms://" + DemoService.class.getName() + "?version=1.0.0"));
      
XBeanBrokerFactory factory = new XBeanBrokerFactory();
BrokerService broker = factory.createBroker(new URI(JmsProtocolTest.class.getPackage().getName().replace('.', '/') +"/activemq.xml"));
broker.start();

ActiveMQConnectionFactory queueConnectionFactory = new ActiveMQConnectionFactory( "tcp://localhost:61617" );
Queue queue = new ActiveMQQueue("DUBBO");

JmsProtocol jmsProtocol = new JmsProtocol();
jmsProtocol.setQueue(queue);
jmsProtocol.setQueueConnectionFactory(queueConnectionFactory);

      DemoServiceImpl server = new DemoServiceImpl();
      
      URL url = URL.valueOf("jms://" + DemoService.class.getName() + "?version=1.0.0");
      Exporter<DemoService> exporter = jmsProtocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
      Invoker<DemoService> invoker = jmsProtocol.refer(DemoService.class, url);
      DemoService client = proxyFactory.getProxy(invoker);
      
      // test integer
      int i = client.test(1);
      Assert.assertEquals(2, i);
      
      // test string and integer
      String result = client.test("haha",0);
      Assert.assertEquals("haha:1", result);
      
      // test timeout
      try {
      	client.testTimeout(1000);
      	Assert.fail("timeout doesn't work");
} catch (Exception e) {
	Assert.assertTrue( e instanceof RpcException);
}
      
      invoker.destroy();
      exporter.unexport();
      
      broker.stop();
  }
 
Example 19
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();
        }
    }
}
 
Example 20
Source File: SearchSenderTest.java    From oneops with Apache License 2.0 4 votes vote down vote up
private void stopBroker(BrokerService searchBroker) throws Exception {
	searchBroker.stop();
	searchBroker.waitUntilStopped();
}