org.apache.rocketmq.common.BrokerConfig Java Examples

The following examples show how to use org.apache.rocketmq.common.BrokerConfig. 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: ConsumeQueueTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #2
Source File: MessageStoreTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore createMessageStore(String base, boolean createAbort) throws Exception {
    baseDirs.add(base);
    MessageStoreConfig storeConfig = new MessageStoreConfig();
    storeConfig.setMappedFileSizeCommitLog(1024 * 100);
    storeConfig.setMappedFileSizeConsumeQueue(1024);
    storeConfig.setMaxHashSlotNum(100);
    storeConfig.setMaxIndexNum(100 * 10);
    storeConfig.setStorePathRootDir(base);
    storeConfig.setStorePathCommitLog(base + File.separator + "commitlog");
    storeConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
    DefaultMessageStore defaultMessageStore = new DefaultMessageStore(storeConfig,  new BrokerStatsManager("CommitlogTest"), (topic, queueId, logicOffset, tagsCode, msgStoreTime, filterBitMap, properties) -> {

    }, new BrokerConfig());

    if (createAbort) {
        String fileName = StorePathConfigHelper.getAbortFile(storeConfig.getStorePathRootDir());
        makeSureFileExists(fileName);
    }
    Assert.assertTrue(defaultMessageStore.load());
    defaultMessageStore.start();
    return defaultMessageStore;
}
 
Example #3
Source File: ConsumeQueueTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #4
Source File: ConsumeQueueTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                                 long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #5
Source File: ScheduleMessageServiceTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMessageDelayLevel(testMessageDelayLevel);
    messageStoreConfig.setMappedFileSizeCommitLog(commitLogFileSize);
    messageStoreConfig.setMappedFileSizeConsumeQueue(cqFileSize);
    messageStoreConfig.setMappedFileSizeConsumeQueueExt(cqExtFileSize);
    messageStoreConfig.setMessageIndexEnable(false);
    messageStoreConfig.setEnableConsumeQueueExt(true);
    messageStoreConfig.setStorePathRootDir(storePath);
    messageStoreConfig.setStorePathCommitLog(storePath + File.separator + "commitlog");

    brokerConfig = new BrokerConfig();
    BrokerStatsManager manager = new BrokerStatsManager(brokerConfig.getBrokerClusterName());
    messageStore = new DefaultMessageStore(messageStoreConfig, manager, new MyMessageArrivingListener(), new BrokerConfig());

    assertThat(messageStore.load()).isTrue();

    messageStore.start();
    scheduleMessageService = messageStore.getScheduleMessageService();
}
 
Example #6
Source File: DefaultMessageStoreTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test(expected = OverlappingFileLockException.class)
public void test_repate_restart() throws Exception {
    long totalMsgs = 100;
    QUEUE_TOTAL = 1;
    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8);
    messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 4);
    messageStoreConfig.setMaxHashSlotNum(100);
    messageStoreConfig.setMaxIndexNum(100 * 10);
    MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig());

    boolean load = master.load();
    assertTrue(load);

    try {
        master.start();
        master.start();
    } finally {
        master.shutdown();
        master.destroy();
    }
}
 
Example #7
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static BrokerController createAndStartBroker(String nsAddr) {
    String baseDir = createBaseDir();
    BrokerConfig brokerConfig = new BrokerConfig();
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    NettyClientConfig nettyClientConfig = new NettyClientConfig();
    MessageStoreConfig storeConfig = new MessageStoreConfig();
    brokerConfig.setBrokerName(BROKER_NAME_PREFIX + BROKER_INDEX.getAndIncrement());
    brokerConfig.setBrokerIP1("127.0.0.1");
    brokerConfig.setNamesrvAddr(nsAddr);
    storeConfig.setStorePathRootDir(baseDir);
    storeConfig.setStorePathCommitLog(baseDir + SEP + "commitlog");
    storeConfig.setHaListenPort(8000 + random.nextInt(1000));
    nettyServerConfig.setListenPort(10000 + random.nextInt(1000));
    BrokerController brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, storeConfig);
    try {
        Assert.assertTrue(brokerController.initialize());
        logger.info("Broker Start name:{} addr:{}", brokerConfig.getBrokerName(), brokerController.getBrokerAddr());
        brokerController.start();
    } catch (Exception e) {
        logger.info("Broker start failed");
        System.exit(1);
    }
    BROKER_CONTROLLERS.add(brokerController);
    return brokerController;
}
 
Example #8
Source File: IntegrationTestBase.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static BrokerController createAndStartBroker(String nsAddr) {
    String baseDir = createBaseDir();
    BrokerConfig brokerConfig = new BrokerConfig();
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    NettyClientConfig nettyClientConfig = new NettyClientConfig();
    MessageStoreConfig storeConfig = new MessageStoreConfig();
    brokerConfig.setBrokerName(BROKER_NAME_PREFIX + BROKER_INDEX.getAndIncrement());
    brokerConfig.setBrokerIP1("127.0.0.1");
    brokerConfig.setNamesrvAddr(nsAddr);
    storeConfig.setStorePathRootDir(baseDir);
    storeConfig.setStorePathCommitLog(baseDir + SEP + "commitlog");
    storeConfig.setHaListenPort(8000 + random.nextInt(1000));
    nettyServerConfig.setListenPort(10000 + random.nextInt(1000));
    BrokerController brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, storeConfig);
    try {
        Assert.assertTrue(brokerController.initialize());
        logger.info("Broker Start name:{} addr:{}", brokerConfig.getBrokerName(), brokerController.getBrokerAddr());
        brokerController.start();
    } catch (Exception e) {
        logger.info("Broker start failed");
        System.exit(1);
    }
    BROKER_CONTROLLERS.add(brokerController);
    return brokerController;
}
 
Example #9
Source File: ConsumeQueueTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #10
Source File: ConsumeQueueTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #11
Source File: DefaultMessageStoreTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test(expected = OverlappingFileLockException.class)
public void test_repate_restart() throws Exception {
    QUEUE_TOTAL = 1;
    MessageBody = StoreMessage.getBytes();

    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8);
    messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 4);
    messageStoreConfig.setMaxHashSlotNum(100);
    messageStoreConfig.setMaxIndexNum(100 * 10);
    MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig());

    boolean load = master.load();
    assertTrue(load);

    try {
        master.start();
        master.start();
    } finally {
        master.shutdown();
        master.destroy();
    }
}
 
Example #12
Source File: ConsumeQueueTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #13
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 #14
Source File: DeFiReplyMessageProcessorTest.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    deFiBrokerController = spy(new DeFiBrokerController(new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig(), deFiBusBrokerConfig));
    channelHandlerContext = mock(ChannelHandlerContext.class);
    messageStore = mock(MessageStore.class);
    DeFiBusBroker2Client broker2Client = mock(DeFiBusBroker2Client.class);
    when(this.deFiBrokerController.getDeFiBusBroker2Client()).thenReturn(broker2Client);
    when(broker2Client.pushRRReplyMessageToClient(any(), any(), any())).thenReturn(true);
    Channel channel = mock(Channel.class);
    when(channel.isActive()).thenReturn(true);
    ClientChannelInfo channelInfo = mock(ClientChannelInfo.class);
    when(channelInfo.getChannel()).thenReturn(channel);
    DeFiProducerManager mockProducer = mock(DeFiProducerManager.class);
    when(mockProducer.getClientChannel(anyString())).thenReturn(channelInfo);
    when(this.deFiBrokerController.getProducerManager()).thenReturn(mockProducer);
    this.deFiBrokerController.setMessageStore(this.messageStore);
    when(this.messageStore.now()).thenReturn(System.currentTimeMillis());
    AppendMessageResult appendMessageResult = new AppendMessageResult(AppendMessageStatus.PUT_OK, 0, 0, "00000000000000000000000000000000", messageStore.now(), 0L, 0);
    when(this.messageStore.putMessage(any())).thenReturn(new PutMessageResult(PutMessageStatus.PUT_OK, appendMessageResult));
    when(channel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(channelHandlerContext.channel()).thenReturn(channel);
    deFiReplyMessageProcessor = new DeFiReplyMessageProcessor(this.deFiBrokerController);
}
 
Example #15
Source File: BrokerControllerTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the controller can be properly stopped and started.
 *
 * @throws Exception If fails.
 */
@Test
public void testBrokerRestart() throws Exception {
    BrokerController brokerController = new BrokerController(
        new BrokerConfig(),
        new NettyServerConfig(),
        new NettyClientConfig(),
        new MessageStoreConfig());
    assertThat(brokerController.initialize());
    brokerController.start();
    brokerController.shutdown();
}
 
Example #16
Source File: DefaultMessageStoreTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testGroupCommit() throws Exception {
    long totalMsgs = 100;
    QUEUE_TOTAL = 1;
    MessageBody = StoreMessage.getBytes();
    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8);
    messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH);
    MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig());
    boolean load = master.load();
    assertTrue(load);

    master.start();
    try {
        for (long i = 0; i < totalMsgs; i++) {
            master.putMessage(buildMessage());
        }

        for (long i = 0; i < totalMsgs; i++) {
            GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null);
            assertThat(result).isNotNull();
            result.release();

        }
    } finally {
        master.shutdown();
        master.destroy();
    }
}
 
Example #17
Source File: BrokerControllerTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the controller can be properly stopped and started.
 *
 * @throws Exception If fails.
 */
@Test
public void testBrokerRestart() throws Exception {
    for (int i = 0; i < 2; i++) {
        BrokerController brokerController = new BrokerController(//
            new BrokerConfig(), //
            new NettyServerConfig(), //
            new NettyClientConfig(), //
            new MessageStoreConfig());
        assertThat(brokerController.initialize());
        brokerController.start();
        brokerController.shutdown();
    }
}
 
Example #18
Source File: StatsItemSet.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public StatsItemSet(String statsName, ScheduledExecutorService scheduledExecutorService, Logger log,
    BrokerConfig brokerConfig) {
    this.statsName = statsName;
    this.scheduledExecutorService = scheduledExecutorService;
    this.log = log;
    this.brokerConfig = brokerConfig;
    this.init();
}
 
Example #19
Source File: StatsItem.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public StatsItem(String statsName, String statsKey, ScheduledExecutorService scheduledExecutorService,
    Logger log, BrokerConfig brokerConfig) {
    this.statsName = statsName;
    this.statsKey = statsKey;
    this.scheduledExecutorService = scheduledExecutorService;
    this.log = log;
    this.brokerConfig = brokerConfig;
}
 
Example #20
Source File: MessageStoreWithFilterTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
protected DefaultMessageStore gen(ConsumerFilterManager filterManager) throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(
        commitLogFileSize, cqFileSize, true, cqExtFileSize
    );

    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    brokerConfig.setMaxErrorRateOfBloomFilter(20);
    brokerConfig.setExpectConsumerNumUseFilter(64);

    DefaultMessageStore master = new DefaultMessageStore(
        messageStoreConfig,
        new BrokerStatsManager(brokerConfig.getBrokerClusterName()),
        new MessageArrivingListener() {
            @Override
            public void arriving(String topic, int queueId, long logicOffset, long tagsCode,
                                 long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
            }
        }
        , brokerConfig);

    master.getDispatcherList().addFirst(new CommitLogDispatcher() {
        @Override
        public void dispatch(DispatchRequest request) {
            try {
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));

    assertThat(master.load()).isTrue();

    master.start();

    return master;
}
 
Example #21
Source File: DefaultMessageStoreTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
private MessageStore buildMessageStore() throws Exception {
    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 1024 * 10);
    messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 1024 * 10);
    messageStoreConfig.setMaxHashSlotNum(10000);
    messageStoreConfig.setMaxIndexNum(100 * 100);
    messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH);
    messageStoreConfig.setFlushIntervalConsumeQueue(1);
    return new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager("simpleTest"), new MyMessageArrivingListener(), new BrokerConfig());
}
 
Example #22
Source File: BrokerControllerTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the controller can be properly stopped and started.
 *
 * @throws Exception If fails.
 */
@Test
public void testBrokerRestart() throws Exception {
    for (int i = 0; i < 2; i++) {
        BrokerController brokerController = new BrokerController(//
            new BrokerConfig(), //
            new NettyServerConfig(), //
            new NettyClientConfig(), //
            new MessageStoreConfig());
        assertThat(brokerController.initialize());
        brokerController.start();
        brokerController.shutdown();
    }
}
 
Example #23
Source File: CommitLogDispatcherCalcBitMapTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatch_blankFilterData() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);

    ConsumerFilterManager filterManager = new ConsumerFilterManager();

    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig,
        filterManager);

    for (int i = 0; i < 10; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));

        String topic = "topic" + i;

        DispatchRequest dispatchRequest = new DispatchRequest(
            topic,
            0,
            i * 100 + 123,
            100,
            (long) ("tags" + i).hashCode(),
            System.currentTimeMillis(),
            i,
            null,
            UUID.randomUUID().toString(),
            0,
            0,
            properties
        );

        calcBitMap.dispatch(dispatchRequest);

        assertThat(dispatchRequest.getBitMap()).isNull();
    }
}
 
Example #24
Source File: CommitLogDispatcherCalcBitMapTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatch_blankFilterData() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);

    ConsumerFilterManager filterManager = new ConsumerFilterManager();

    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig,
        filterManager);

    for (int i = 0; i < 10; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));

        String topic = "topic" + i;

        DispatchRequest dispatchRequest = new DispatchRequest(
            topic,
            0,
            i * 100 + 123,
            100,
            (long) ("tags" + i).hashCode(),
            System.currentTimeMillis(),
            i,
            null,
            UUID.randomUUID().toString(),
            0,
            0,
            properties
        );

        calcBitMap.dispatch(dispatchRequest);

        assertThat(dispatchRequest.getBitMap()).isNull();
    }
}
 
Example #25
Source File: BrokerStartupTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
// 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        // NettyServerConfig 配置
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(10911);
        // BrokerConfig 配置
        final BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setBrokerName("broker-a");
        brokerConfig.setNamesrvAddr("127.0.0.1:9876");
        // MessageStoreConfig 配置
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        messageStoreConfig.setDeleteWhen("04");
        messageStoreConfig.setFileReservedTime(48);
        messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
        messageStoreConfig.setDuplicationEnable(false);

//        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/百度云同步盘/开发/Javascript/Story/incubator-rocketmq/conf/broker.conf");
        // 创建 BrokerController 对象,并启动
        BrokerController brokerController = new BrokerController(//
                brokerConfig, //
                nettyServerConfig, //
                new NettyClientConfig(), //
                messageStoreConfig);
        brokerController.initialize();
        brokerController.start();
        // 睡觉,就不起来
        System.out.println("你猜");
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #26
Source File: BrokerControllerTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testBrokerRestart() throws Exception {
    BrokerController brokerController = new BrokerController(
        new BrokerConfig(),
        new NettyServerConfig(),
        new NettyClientConfig(),
        new MessageStoreConfig());
    assertThat(brokerController.initialize());
    brokerController.start();
    brokerController.shutdown();
}
 
Example #27
Source File: MessageStorePluginContext.java    From rocketmq-read 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 #28
Source File: QueueListeningMonitorTest.java    From DeFiBus with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
    deFiBrokerController = new DeFiBrokerController(
        new BrokerConfig(),
        new NettyServerConfig(),
        new NettyClientConfig(),
        new MessageStoreConfig(),
        new DeFiBusBrokerConfig());
    assertThat(deFiBrokerController.initialize());

    Field field = DeFiBrokerController.class.getDeclaredField("queueListeningMonitor");
    field.setAccessible(true);
    field.set(deFiBrokerController, queueListeningMonitor);
}
 
Example #29
Source File: CommitLogDispatcherCalcBitMapTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatch_blankFilterData() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);

    ConsumerFilterManager filterManager = new ConsumerFilterManager();

    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig,
        filterManager);

    for (int i = 0; i < 10; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));

        String topic = "topic" + i;

        DispatchRequest dispatchRequest = new DispatchRequest(
            topic,
            0,
            i * 100 + 123,
            100,
            (long) ("tags" + i).hashCode(),
            System.currentTimeMillis(),
            i,
            null,
            UUID.randomUUID().toString(),
            0,
            0,
            properties
        );

        calcBitMap.dispatch(dispatchRequest);

        assertThat(dispatchRequest.getBitMap()).isNull();
    }
}
 
Example #30
Source File: DefaultMessageStore.java    From DDMQ with Apache License 2.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.allocateMappedFileService = new AllocateMappedFileService(this);
    this.commitLog = new CommitLog(this);
    this.consumeQueueTable = new ConcurrentHashMap<>(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.reputMessageService = new ReputMessageService();

    this.scheduleMessageService = new ScheduleMessageService(this);

    this.transientStorePool = new TransientStorePool(messageStoreConfig);

    if (messageStoreConfig.isTransientStorePoolEnable()) {
        this.transientStorePool.init();
    }

    this.allocateMappedFileService.start();

    this.indexService.start();

    this.dispatcherList = new LinkedList<>();
    this.dispatcherList.addLast(new CommitLogDispatcherBuildConsumeQueue());
    this.dispatcherList.addLast(new CommitLogDispatcherBuildIndex());

    File file = new File(StorePathConfigHelper.getLockFile(messageStoreConfig.getStorePathRootDir()));
    MappedFile.ensureDirOK(file.getParent());
    lockFile = new RandomAccessFile(file, "rw");
}