Java Code Examples for org.apache.rocketmq.broker.BrokerController#shutdown()

The following examples show how to use org.apache.rocketmq.broker.BrokerController#shutdown() . 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: AbstractTestCase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * Start rocketmq broker service
 * @throws Exception
 */
private static void startBroker() throws Exception {

    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));

    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setNamesrvAddr(nameServer);
    brokerConfig.setBrokerId(MixAll.MASTER_ID);
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(10911);
    NettyClientConfig nettyClientConfig = new NettyClientConfig();
    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();

    brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, messageStoreConfig);
    boolean initResult = brokerController.initialize();
    if (!initResult) {
        brokerController.shutdown();
        throw new Exception();
    }
    brokerController.start();
}
 
Example 2
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override public void run() {
    for (NamesrvController namesrvController : NAMESRV_CONTROLLERS) {
        if (namesrvController != null) {
            namesrvController.shutdown();
        }
    }
    for (BrokerController brokerController : BROKER_CONTROLLERS) {
        if (brokerController != null) {
            brokerController.shutdown();
        }
    }
    for (File file : TMPE_FILES) {
        deleteFile(file);
    }
}
 
Example 3
Source File: IntegrationTestBase.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override public void run() {
    for (NamesrvController namesrvController : NAMESRV_CONTROLLERS) {
        if (namesrvController != null) {
            namesrvController.shutdown();
        }
    }
    for (BrokerController brokerController : BROKER_CONTROLLERS) {
        if (brokerController != null) {
            brokerController.shutdown();
        }
    }
    for (File file : TMPE_FILES) {
        deleteFile(file);
    }
}
 
Example 4
Source File: DLedgerProduceAndConsumeIT.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void testProduceAndConsume() throws Exception {
    String cluster = UUID.randomUUID().toString();
    String brokerName = UUID.randomUUID().toString();
    String selfId = "n0";
    String peers = String.format("n0-localhost:%d", nextPort());
    BrokerConfig brokerConfig = buildBrokerConfig(cluster, brokerName);
    MessageStoreConfig storeConfig = buildStoreConfig(brokerName, peers, selfId);
    BrokerController brokerController = IntegrationTestBase.createAndStartBroker(storeConfig, brokerConfig);
    Thread.sleep(3000);

    Assert.assertEquals(BrokerRole.SYNC_MASTER, storeConfig.getBrokerRole());


    String topic = UUID.randomUUID().toString();
    String consumerGroup = UUID.randomUUID().toString();
    IntegrationTestBase.initTopic(topic, BaseConf.nsAddr, cluster, 1);
    DefaultMQProducer producer = ProducerFactory.getRMQProducer(BaseConf.nsAddr);
    DefaultMQPullConsumer consumer = ConsumerFactory.getRMQPullConsumer(BaseConf.nsAddr, consumerGroup);

    for (int i = 0; i < 10; i++) {
        Message message = new Message();
        message.setTopic(topic);
        message.setBody(("Hello" + i).getBytes());
        SendResult sendResult = producer.send(message);
        Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());
        Assert.assertEquals(0, sendResult.getMessageQueue().getQueueId());
        Assert.assertEquals(brokerName, sendResult.getMessageQueue().getBrokerName());
        Assert.assertEquals(i, sendResult.getQueueOffset());
        Assert.assertNotNull(sendResult.getMsgId());
        Assert.assertNotNull(sendResult.getOffsetMsgId());
    }

    Thread.sleep(500);
    Assert.assertEquals(0, brokerController.getMessageStore().getMinOffsetInQueue(topic, 0));
    Assert.assertEquals(10, brokerController.getMessageStore().getMaxOffsetInQueue(topic, 0));

    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0);
    PullResult pullResult= consumer.pull(messageQueue, "*", 0, 32);
    Assert.assertEquals(PullStatus.FOUND, pullResult.getPullStatus());
    Assert.assertEquals(10, pullResult.getMsgFoundList().size());

    for (int i = 0; i < 10; i++) {
        MessageExt messageExt = pullResult.getMsgFoundList().get(i);
        Assert.assertEquals(i, messageExt.getQueueOffset());
        Assert.assertArrayEquals(("Hello" + i).getBytes(), messageExt.getBody());
    }

    producer.shutdown();
    consumer.shutdown();
    brokerController.shutdown();
}