com.alibaba.rocketmq.store.config.MessageStoreConfig Java Examples

The following examples show how to use com.alibaba.rocketmq.store.config.MessageStoreConfig. 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: TopicConfigManagerTest.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Test
public void test_flushTopicConfig() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    TopicConfigManager topicConfigManager = new TopicConfigManager(brokerController);

    TopicConfig topicConfig = topicConfigManager.createTopicInSendMessageMethod("TestTopic_SEND",
        MixAll.DEFAULT_TOPIC, null, 4, 0);
    assertTrue(topicConfig != null);

    System.out.println(topicConfig);

    for (int i = 0; i < 10; i++) {
        String topic = "UNITTEST-" + i;
        topicConfig = topicConfigManager.createTopicInSendMessageMethod(topic, MixAll.DEFAULT_TOPIC, null,
            4, 0);
        assertTrue(topicConfig != null);
    }

    topicConfigManager.persist();

    brokerController.shutdown();
}
 
Example #2
Source File: BrokerController.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public BrokerController(final BrokerConfig brokerConfig, final NettyServerConfig nettyServerConfig,
        final NettyClientConfig nettyClientConfig, final MessageStoreConfig messageStoreConfig) {
    this.brokerConfig = brokerConfig;
    this.nettyServerConfig = nettyServerConfig;
    this.nettyClientConfig = nettyClientConfig;
    this.messageStoreConfig = messageStoreConfig;
    this.consumerOffsetManager = new ConsumerOffsetManager(this);
    this.topicConfigManager = new TopicConfigManager(this);
    this.pullMessageProcessor = new PullMessageProcessor(this);
    this.pullRequestHoldService = new PullRequestHoldService(this);
    this.consumerIdsChangeListener = new DefaultConsumerIdsChangeListener(this);
    this.consumerManager = new ConsumerManager(this.consumerIdsChangeListener);
    this.producerManager = new ProducerManager();
    this.clientHousekeepingService = new ClientHousekeepingService(this);
    this.broker2Client = new Broker2Client(this);
    this.subscriptionGroupManager = new SubscriptionGroupManager(this);
    this.brokerOuterAPI = new BrokerOuterAPI(nettyClientConfig);
    this.filterServerManager = new FilterServerManager(this);

    if (this.brokerConfig.getNamesrvAddr() != null) {
        // 更新netty client 的nameserver地址
        this.brokerOuterAPI.updateNameServerAddressList(this.brokerConfig.getNamesrvAddr());
        log.info("user specfied name server address: {}", this.brokerConfig.getNamesrvAddr());
    }
    // 构造broker和broker slave 节点间数据同步的对象
    this.slaveSynchronize = new SlaveSynchronize(this);
    // 发送消息任务队列
    this.sendThreadPoolQueue =
            new LinkedBlockingQueue<Runnable>(this.brokerConfig.getSendThreadPoolQueueCapacity());
    // 拉取消息任务队列
    this.pullThreadPoolQueue =
            new LinkedBlockingQueue<Runnable>(this.brokerConfig.getPullThreadPoolQueueCapacity());
    // 初始化broker状态管理类
    this.brokerStatsManager = new BrokerStatsManager(this.brokerConfig.getBrokerClusterName());
    // 设置broker IP和端口
    this.setStoreHost(new InetSocketAddress(this.getBrokerConfig().getBrokerIP1(),
        this.getNettyServerConfig().getListenPort()));
}
 
Example #3
Source File: ConsumerOffsetManagerTest.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Test
public void test_flushConsumerOffset() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    ConsumerOffsetManager consumerOffsetManager = new ConsumerOffsetManager(brokerController);

    Random random = new Random();

    for (int i = 0; i < 100; i++) {
        String group = "DIANPU_GROUP_" + i;
        for (int id = 0; id < 16; id++) {
            consumerOffsetManager.commitOffset(group, "TOPIC_A", id,
                random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(group, "TOPIC_B", id,
                random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(group, "TOPIC_C", id,
                random.nextLong() % 1024 * 1024 * 1024);
        }
    }

    consumerOffsetManager.persist();

    brokerController.shutdown();
}
 
Example #4
Source File: DefaultMessageStore.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final BrokerStatsManager brokerStatsManager,
                           final MessageArrivingListener messageArrivingListener, final TransactionCheckExecuter transactionCheckExecuter,final BrokerConfig brokerConfig) throws IOException {
    this.messageArrivingListener = messageArrivingListener;
    this.transactionCheckExecuter = transactionCheckExecuter;
    this.brokerConfig = brokerConfig;
    this.messageStoreConfig = messageStoreConfig;
    this.brokerStatsManager = brokerStatsManager;
    this.allocateMapedFileService = new AllocateMapedFileService(this);
    this.commitLog = new CommitLog(this);
    this.consumeQueueTable = new ConcurrentHashMap<String/* topic */, ConcurrentHashMap<Integer/* queueId */, ConsumeQueue>>(32);

    this.flushConsumeQueueService = new FlushConsumeQueueService();
    this.cleanCommitLogService = new CleanCommitLogService();
    this.cleanConsumeQueueService = new CleanConsumeQueueService();
    this.storeStatsService = new StoreStatsService();
    this.indexService = new IndexService(this);
    this.haService = new HAService(this);
    this.transactionStateService = new TransactionStateService(this);

    this.reputMessageService = new ReputMessageService();

    this.scheduleMessageService = new ScheduleMessageService(this);


    this.allocateMapedFileService.start();

    this.indexService.start();
}
 
Example #5
Source File: TopicConfigManagerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void test_flushTopicConfig() throws Exception {
    BrokerController brokerController = new BrokerController(//
            new BrokerConfig(), //
            new NettyServerConfig(), //
            new NettyClientConfig(), //
            new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    TopicConfigManager topicConfigManager = new TopicConfigManager(brokerController);

    TopicConfig topicConfig =
            topicConfigManager.createTopicInSendMessageMethod("TestTopic_SEND", MixAll.DEFAULT_TOPIC,
                    null, 4, 0);
    assertTrue(topicConfig != null);

    System.out.println(topicConfig);

    for (int i = 0; i < 10; i++) {
        String topic = "UNITTEST-" + i;
        topicConfig =
                topicConfigManager
                        .createTopicInSendMessageMethod(topic, MixAll.DEFAULT_TOPIC, null, 4, 0);
        assertTrue(topicConfig != null);
    }

    topicConfigManager.persist();

    brokerController.shutdown();
}
 
Example #6
Source File: BrokerController.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public BrokerController(//
        final BrokerConfig brokerConfig, //
        final NettyServerConfig nettyServerConfig, //
        final NettyClientConfig nettyClientConfig, //
        final MessageStoreConfig messageStoreConfig //
) {
    this.brokerConfig = brokerConfig;
    this.nettyServerConfig = nettyServerConfig;
    this.nettyClientConfig = nettyClientConfig;
    this.messageStoreConfig = messageStoreConfig;
    this.consumerOffsetManager = new ConsumerOffsetManager(this);
    this.topicConfigManager = new TopicConfigManager(this);
    this.pullMessageProcessor = new PullMessageProcessor(this);
    this.pullRequestHoldService = new PullRequestHoldService(this);
    this.messageArrivingListener = new NotifyMessageArrivingListener(this.pullRequestHoldService);
    this.consumerIdsChangeListener = new DefaultConsumerIdsChangeListener(this);
    this.consumerManager = new ConsumerManager(this.consumerIdsChangeListener);
    this.producerManager = new ProducerManager();
    this.clientHousekeepingService = new ClientHousekeepingService(this);
    this.broker2Client = new Broker2Client(this);
    this.subscriptionGroupManager = new SubscriptionGroupManager(this);
    this.brokerOuterAPI = new BrokerOuterAPI(nettyClientConfig);
    this.filterServerManager = new FilterServerManager(this);

    if (this.brokerConfig.getNamesrvAddr() != null) {
        this.brokerOuterAPI.updateNameServerAddressList(this.brokerConfig.getNamesrvAddr());
        log.info("user specfied name server address: {}", this.brokerConfig.getNamesrvAddr());
    }

    this.slaveSynchronize = new SlaveSynchronize(this);

    this.sendThreadPoolQueue = new LinkedBlockingQueue<Runnable>(this.brokerConfig.getSendThreadPoolQueueCapacity());

    this.pullThreadPoolQueue = new LinkedBlockingQueue<Runnable>(this.brokerConfig.getPullThreadPoolQueueCapacity());

    this.brokerStatsManager = new BrokerStatsManager(this.brokerConfig.getBrokerClusterName());
    this.setStoreHost(new InetSocketAddress(this.getBrokerConfig().getBrokerIP1(), this.getNettyServerConfig().getListenPort()));
}
 
Example #7
Source File: ConsumerOffsetManagerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void test_flushConsumerOffset() throws Exception {
    BrokerController brokerController = new BrokerController(//
            new BrokerConfig(), //
            new NettyServerConfig(), //
            new NettyClientConfig(), //
            new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    ConsumerOffsetManager consumerOffsetManager = new ConsumerOffsetManager(brokerController);

    Random random = new Random();

    for (int i = 0; i < 100; i++) {
        String group = "DIANPU_GROUP_" + i;
        for (int id = 0; id < 16; id++) {
            consumerOffsetManager.commitOffset(null, group, "TOPIC_A", id,
                    random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(null, group, "TOPIC_B", id,
                    random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(null, group, "TOPIC_C", id,
                    random.nextLong() % 1024 * 1024 * 1024);
        }
    }

    consumerOffsetManager.persist();

    brokerController.shutdown();
}
 
Example #8
Source File: MessageStorePluginContext.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public MessageStorePluginContext(MessageStoreConfig messageStoreConfig,
                                 BrokerStatsManager brokerStatsManager, MessageArrivingListener messageArrivingListener,
                                 BrokerConfig brokerConfig) {
    super();
    this.messageStoreConfig = messageStoreConfig;
    this.brokerStatsManager = brokerStatsManager;
    this.messageArrivingListener = messageArrivingListener;
    this.brokerConfig = brokerConfig;
}
 
Example #9
Source File: RecoverTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void readMessage(final long msgCnt) throws Exception {
    System.out.println("================================================================");
    QUEUE_TOTAL = 3;

    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);
    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    storeRead = new DefaultMessageStore(messageStoreConfig, null, null, null);
    boolean loadResult = storeRead.load();
    assertTrue(loadResult);

    storeRead.start();

    long readCnt = 0;
    for (int queueId = 0; queueId < QUEUE_TOTAL; queueId++) {
        for (long offset = 0;;) {
            GetMessageResult result = storeRead.getMessage("GROUP_A", "TOPIC_A", queueId, offset, 1024 * 1024, null);
            if (result.getStatus() == GetMessageStatus.FOUND) {
                System.out.println(queueId + "\t" + result.getMessageCount());
                this.veryReadMessage(queueId, offset, result.getMessageBufferList());
                offset += result.getMessageCount();
                readCnt += result.getMessageCount();
                result.release();
            }
            else {
                break;
            }
        }
    }

    System.out.println("readCnt = " + readCnt);
    assertTrue(readCnt == msgCnt);

    System.out.println("========================readMessage OK========================================");
}
 
Example #10
Source File: RecoverTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void writeMessage(boolean normal, boolean first) throws Exception {
    System.out.println("================================================================");
    long totalMsgs = 1000;
    QUEUE_TOTAL = 3;

    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);
    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    MessageStore messageStore = new DefaultMessageStore(messageStoreConfig, null, null, null);
    if (first) {
        this.storeWrite1 = messageStore;
    }
    else {
        this.storeWrite2 = messageStore;
    }

    boolean loadResult = messageStore.load();
    assertTrue(loadResult);

    messageStore.start();

    for (long i = 0; i < totalMsgs; i++) {

        PutMessageResult result = messageStore.putMessage(buildMessage());

        System.out.println(i + "\t" + result.getAppendMessageResult().getMsgId());
    }

    if (normal) {
        messageStore.shutdown();
    }

    System.out.println("========================writeMessage OK========================================");
}
 
Example #11
Source File: DefaultMessageStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final BrokerStatsManager brokerStatsManager,
        final MessageArrivingListener messageArrivingListener, final BrokerConfig brokerConfig) throws IOException {
    this.messageArrivingListener = messageArrivingListener;
    this.brokerConfig = brokerConfig;
    this.messageStoreConfig = messageStoreConfig;
    this.brokerStatsManager = brokerStatsManager;
    this.allocateMapedFileService = new AllocateMapedFileService(this);
    this.commitLog = new CommitLog(this);
    this.consumeQueueTable = new ConcurrentHashMap<String/* topic */, ConcurrentHashMap<Integer/* queueId */, ConsumeQueue>>(32);

    this.flushConsumeQueueService = new FlushConsumeQueueService();

    //磁盘超过水位进行清理
    this.cleanCommitLogService = new CleanCommitLogService();
    this.cleanConsumeQueueService = new CleanConsumeQueueService();

    this.storeStatsService = new StoreStatsService();
    this.indexService = new IndexService(this);
    this.haService = new HAService(this);

    //异步构建CQ和索引文件的服务。
    this.reputMessageService = new ReputMessageService();
    //延迟消息投递服务
    this.scheduleMessageService = new ScheduleMessageService(this);

    this.allocateMapedFileService.start();
    this.indexService.start();
}
 
Example #12
Source File: TopicConfigManagerTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_flushTopicConfig() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    TopicConfigManager topicConfigManager = new TopicConfigManager(brokerController);

    TopicConfig topicConfig =
            topicConfigManager.createTopicInSendMessageMethod("TestTopic_SEND", MixAll.DEFAULT_TOPIC,
                null, 4, 0);
    assertTrue(topicConfig != null);

    System.out.println(topicConfig);

    for (int i = 0; i < 10; i++) {
        String topic = "UNITTEST-" + i;
        topicConfig =
                topicConfigManager
                    .createTopicInSendMessageMethod(topic, MixAll.DEFAULT_TOPIC, null, 4, 0);
        assertTrue(topicConfig != null);
    }

    topicConfigManager.persist();

    brokerController.shutdown();
}
 
Example #13
Source File: ConsumerOffsetManagerTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test_flushConsumerOffset() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);
    brokerController.start();

    ConsumerOffsetManager consumerOffsetManager = new ConsumerOffsetManager(brokerController);

    Random random = new Random();

    for (int i = 0; i < 100; i++) {
        String group = "DIANPU_GROUP_" + i;
        for (int id = 0; id < 16; id++) {
            consumerOffsetManager.commitOffset(group, "TOPIC_A", id,
                random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(group, "TOPIC_B", id,
                random.nextLong() % 1024 * 1024 * 1024);
            consumerOffsetManager.commitOffset(group, "TOPIC_C", id,
                random.nextLong() % 1024 * 1024 * 1024);
        }
    }

    consumerOffsetManager.persist();

    brokerController.shutdown();
}
 
Example #14
Source File: DefaultMessageStore.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public DefaultMessageStore(final MessageStoreConfig messageStoreConfig,
        final BrokerStatsManager brokerStatsManager) throws IOException {
    this.messageStoreConfig = messageStoreConfig;
    this.brokerStatsManager = brokerStatsManager;
    this.allocateMapedFileService = new AllocateMapedFileService();
    this.commitLog = new CommitLog(this);
    this.consumeQueueTable =
            new ConcurrentHashMap<String/* topic */, ConcurrentHashMap<Integer/* queueId */, ConsumeQueue>>(
                32);

    this.flushConsumeQueueService = new FlushConsumeQueueService();
    this.cleanCommitLogService = new CleanCommitLogService();
    this.cleanConsumeQueueService = new CleanConsumeQueueService();
    this.dispatchMessageService =
            new DispatchMessageService(this.messageStoreConfig.getPutMsgIndexHightWater());
    this.storeStatsService = new StoreStatsService();
    this.indexService = new IndexService(this);
    this.haService = new HAService(this);

    switch (this.messageStoreConfig.getBrokerRole()) {
    case SLAVE:
        this.reputMessageService = new ReputMessageService();
        // reputMessageService依赖scheduleMessageService做定时消息的恢复,确保储备数据一致
        this.scheduleMessageService = new ScheduleMessageService(this);
        break;
    case ASYNC_MASTER:
    case SYNC_MASTER:
        this.reputMessageService = null;
        this.scheduleMessageService = new ScheduleMessageService(this);
        break;
    default:
        this.reputMessageService = null;
        this.scheduleMessageService = null;
    }

    // load过程依赖此服务,所以提前启动
    this.allocateMapedFileService.start();
    this.dispatchMessageService.start();
    // 因为下面的recover会分发请求到索引服务,如果不启动,分发过程会被流控
    this.indexService.start();
}
 
Example #15
Source File: SendMessageTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Test
public void test_sendMessage() throws Exception {
    BrokerController brokerController = new BrokerController(//
            new BrokerConfig(), //
            new NettyServerConfig(), //
            new NettyClientConfig(), //
            new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);

    brokerController.start();

    MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null, null, null);
    client.start();

    for (int i = 0; i < 100000; i++) {
        String topic = "UnitTestTopic_" + i % 3;
        Message msg = new Message(topic, "TAG1 TAG2", "100200300", ("Hello, Nice world\t" + i).getBytes());
        msg.setDelayTimeLevel(i % 3 + 1);

        try {
            SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
            requestHeader.setProducerGroup("abc");
            requestHeader.setTopic(msg.getTopic());
            requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC);
            requestHeader.setDefaultTopicQueueNums(4);
            requestHeader.setQueueId(i % 4);
            requestHeader.setSysFlag(0);
            requestHeader.setBornTimestamp(System.currentTimeMillis());
            requestHeader.setFlag(msg.getFlag());
            requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));

            SendResult result = client.sendMessage("127.0.0.1:10911", "brokerName", msg, requestHeader, 1000 * 5,
                    CommunicationMode.SYNC, new SendMessageContext(), null);
            System.out.println(i + "\t" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    client.shutdown();

    brokerController.shutdown();
}
 
Example #16
Source File: SendMessageTest.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Test
public void test_sendMessage() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);

    brokerController.start();

    MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null);
    client.start();

    for (int i = 0; i < 100000; i++) {
        String topic = "UnitTestTopic_" + i % 3;
        Message msg =
                new Message(topic, "TAG1 TAG2", "100200300", ("Hello, Nice world\t" + i).getBytes());
        msg.setDelayTimeLevel(i % 3 + 1);

        try {
            SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
            requestHeader.setProducerGroup("abc");
            requestHeader.setTopic(msg.getTopic());
            requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC);
            requestHeader.setDefaultTopicQueueNums(4);
            requestHeader.setQueueId(i % 4);
            requestHeader.setSysFlag(0);
            requestHeader.setBornTimestamp(System.currentTimeMillis());
            requestHeader.setFlag(msg.getFlag());
            requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));

            SendResult result = client.sendMessage("127.0.0.1:10911", "brokerName", msg, requestHeader,
                1000 * 5, CommunicationMode.SYNC, null);
            System.out.println(i + "\t" + result);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    client.shutdown();

    brokerController.shutdown();
}
 
Example #17
Source File: DefaultMessageStore.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #18
Source File: RecoverTest.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void writeMessage(boolean normal, boolean first) throws Exception {
    System.out.println("================================================================");
    long totalMsgs = 1000;
    QUEUE_TOTAL = 3;

    // 构造消息体
    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    // 每个物理映射文件
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);
    // 每个逻辑映射文件
    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    MessageStore messageStore = new DefaultMessageStore(messageStoreConfig, null);
    if (first) {
        this.storeWrite1 = messageStore;
    }
    else {
        this.storeWrite2 = messageStore;
    }

    // 第一步,load已有数据
    boolean loadResult = messageStore.load();
    assertTrue(loadResult);

    // 第二步,启动服务
    messageStore.start();

    // 第三步,发消息
    for (long i = 0; i < totalMsgs; i++) {

        PutMessageResult result = messageStore.putMessage(buildMessage());

        System.out.println(i + "\t" + result.getAppendMessageResult().getMsgId());
    }

    if (normal) {
        // 关闭存储服务
        messageStore.shutdown();
    }

    System.out.println("========================writeMessage OK========================================");
}
 
Example #19
Source File: BrokerController.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #20
Source File: RecoverTest.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void readMessage(final long msgCnt) throws Exception {
    System.out.println("================================================================");
    QUEUE_TOTAL = 3;

    // 构造消息体
    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    // 每个物理映射文件
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);
    // 每个逻辑映射文件
    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    storeRead = new DefaultMessageStore(messageStoreConfig, null);
    // 第一步,load已有数据
    boolean loadResult = storeRead.load();
    assertTrue(loadResult);

    // 第二步,启动服务
    storeRead.start();

    // 第三步,收消息
    long readCnt = 0;
    for (int queueId = 0; queueId < QUEUE_TOTAL; queueId++) {
        for (long offset = 0;;) {
            GetMessageResult result =
                    storeRead.getMessage("GROUP_A", "TOPIC_A", queueId, offset, 1024 * 1024, null);
            if (result.getStatus() == GetMessageStatus.FOUND) {
                System.out.println(queueId + "\t" + result.getMessageCount());
                this.veryReadMessage(queueId, offset, result.getMessageBufferList());
                offset += result.getMessageCount();
                readCnt += result.getMessageCount();
                result.release();
            }
            else {
                break;
            }
        }
    }

    System.out.println("readCnt = " + readCnt);
    assertTrue(readCnt == msgCnt);

    System.out.println("========================readMessage OK========================================");
}
 
Example #21
Source File: RecoverTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void readMessage(final long msgCnt) throws Exception {
    System.out.println("================================================================");
    QUEUE_TOTAL = 3;


    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();

    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);

    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    storeRead = new DefaultMessageStore(messageStoreConfig, null,null, null, null);

    boolean loadResult = storeRead.load();
    assertTrue(loadResult);


    storeRead.start();


    long readCnt = 0;
    for (int queueId = 0; queueId < QUEUE_TOTAL; queueId++) {
        for (long offset = 0; ; ) {
            GetMessageResult result = storeRead.getMessage("GROUP_A", "TOPIC_A", queueId, offset, 1024 * 1024, null);
            if (result.getStatus() == GetMessageStatus.FOUND) {
                System.out.println(queueId + "\t" + result.getMessageCount());
                this.veryReadMessage(queueId, offset, result.getMessageBufferList());
                offset += result.getMessageCount();
                readCnt += result.getMessageCount();
                result.release();
            } else {
                break;
            }
        }
    }

    System.out.println("readCnt = " + readCnt);
    assertTrue(readCnt == msgCnt);

    System.out.println("========================readMessage OK========================================");
}
 
Example #22
Source File: DefaultMessageStore.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #23
Source File: MessageStorePluginContext.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #24
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #25
Source File: BrokerController.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public BrokerController(//
                        final BrokerConfig brokerConfig, //
                        final NettyServerConfig nettyServerConfig, //
                        final NettyClientConfig nettyClientConfig, //
                        final MessageStoreConfig messageStoreConfig //
) {
    this.brokerConfig = brokerConfig;
    this.nettyServerConfig = nettyServerConfig;
    this.nettyClientConfig = nettyClientConfig;
    this.messageStoreConfig = messageStoreConfig;
    this.consumerOffsetManager = new ConsumerOffsetManager(this);
    this.topicConfigManager = new TopicConfigManager(this);
    this.pullMessageProcessor = new PullMessageProcessor(this);
    this.pullRequestHoldService = new PullRequestHoldService(this);
    this.defaultTransactionCheckExecuter = new DefaultTransactionCheckExecuter(this);
    this.messageArrivingListener = new NotifyMessageArrivingListener(this.pullRequestHoldService);
    this.consumerIdsChangeListener = new DefaultConsumerIdsChangeListener(this);
    this.consumerManager = new ConsumerManager(this.consumerIdsChangeListener);
    this.producerManager = new ProducerManager();
    this.clientHousekeepingService = new ClientHousekeepingService(this);
    this.broker2Client = new Broker2Client(this);
    this.subscriptionGroupManager = new SubscriptionGroupManager(this);
    this.brokerOuterAPI = new BrokerOuterAPI(nettyClientConfig);
    this.filterServerManager = new FilterServerManager(this);

    if (this.brokerConfig.getNamesrvAddr() != null) {
        this.brokerOuterAPI.updateNameServerAddressList(this.brokerConfig.getNamesrvAddr());
        log.info("user specfied name server address: {}", this.brokerConfig.getNamesrvAddr());
    }

    this.slaveSynchronize = new SlaveSynchronize(this);

    this.sendThreadPoolQueue = new LinkedBlockingQueue<Runnable>(this.brokerConfig.getSendThreadPoolQueueCapacity());

    this.pullThreadPoolQueue = new LinkedBlockingQueue<Runnable>(this.brokerConfig.getPullThreadPoolQueueCapacity());

    this.brokerStatsManager = new BrokerStatsManager(this.brokerConfig.getBrokerClusterName());
    this.setStoreHost(new InetSocketAddress(this.getBrokerConfig().getBrokerIP1(), this.getNettyServerConfig().getListenPort()));

    this.brokerFastFailure = new BrokerFastFailure(this);
}
 
Example #26
Source File: DefaultMessageStore.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #27
Source File: SendMessageTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void test_sendMessage() throws Exception {
    BrokerController brokerController = new BrokerController(//
        new BrokerConfig(), //
        new NettyServerConfig(), //
        new NettyClientConfig(), //
        new MessageStoreConfig());
    boolean initResult = brokerController.initialize();
    System.out.println("initialize " + initResult);

    brokerController.start();

    MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null, null, null);
    client.start();

    for (int i = 0; i < 100000; i++) {
        String topic = "UnitTestTopic_" + i % 3;
        Message msg = new Message(topic, "TAG1 TAG2", "100200300", ("Hello, Nice world\t" + i).getBytes());
        msg.setDelayTimeLevel(i % 3 + 1);

        try {
            SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
            requestHeader.setProducerGroup("abc");
            requestHeader.setTopic(msg.getTopic());
            requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC);
            requestHeader.setDefaultTopicQueueNums(4);
            requestHeader.setQueueId(i % 4);
            requestHeader.setSysFlag(0);
            requestHeader.setBornTimestamp(System.currentTimeMillis());
            requestHeader.setFlag(msg.getFlag());
            requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));

            SendResult result =
                    client.sendMessage("127.0.0.1:10911", "brokerName", msg, requestHeader, 1000 * 5, CommunicationMode.SYNC, null);
            System.out.println(i + "\t" + result);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    client.shutdown();

    brokerController.shutdown();
}
 
Example #28
Source File: BrokerController.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public MessageStoreConfig getMessageStoreConfig() {
    return messageStoreConfig;
}
 
Example #29
Source File: RecoverTest.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
public void writeMessage(boolean normal, boolean first) throws Exception {
    System.out.println("================================================================");
    long totalMsgs = 1000;
    QUEUE_TOTAL = 3;


    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();

    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 32);

    messageStoreConfig.setMapedFileSizeConsumeQueue(100 * 20);
    messageStoreConfig.setMessageIndexEnable(false);

    MessageStore messageStore = new DefaultMessageStore(messageStoreConfig, null, null, null, null);
    if (first) {
        this.storeWrite1 = messageStore;
    } else {
        this.storeWrite2 = messageStore;
    }


    boolean loadResult = messageStore.load();
    assertTrue(loadResult);


    messageStore.start();


    for (long i = 0; i < totalMsgs; i++) {

        PutMessageResult result = messageStore.putMessage(buildMessage());

        System.out.println(i + "\t" + result.getAppendMessageResult().getMsgId());
    }

    if (normal) {

        messageStore.shutdown();
    }

    System.out.println("========================writeMessage OK========================================");
}