org.apache.rocketmq.remoting.netty.NettyServerConfig Java Examples

The following examples show how to use org.apache.rocketmq.remoting.netty.NettyServerConfig. 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: RemotingServerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
Example #2
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 #3
Source File: IntegrationTestBase.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #4
Source File: IntegrationTestBase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #5
Source File: DefaultRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #6
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 #7
Source File: RemotingServerTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
Example #8
Source File: FiltersrvControllerSlaveTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(30912);
        //
        final FiltersrvConfig filtersrvConfig = new FiltersrvConfig();
        filtersrvConfig.setNamesrvAddr("127.0.0.1:9876");
        filtersrvConfig.setConnectWhichBroker("127.0.0.1:20911");

        // filter 启动
        FiltersrvController filtersrvController = new FiltersrvController(
                filtersrvConfig,
                nettyServerConfig
        );
        boolean initResult = filtersrvController.initialize();
        System.out.println("initResult:" + initResult);
//        filtersrvController
        filtersrvController.start();
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #9
Source File: DefaultRequestProcessorTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #10
Source File: IntegrationTestBase.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #11
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #12
Source File: RemotingServerTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
Example #13
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 #14
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #15
Source File: IntegrationTestBase.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #16
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 #17
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(nextPort());
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed", e);
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #18
Source File: DefaultRequestProcessorTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(InternalLogger.class);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #19
Source File: IntegrationTestBase.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example #20
Source File: RemotingServerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
Example #21
Source File: DefaultRequestProcessorTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    namesrvConfig = new NamesrvConfig();
    nettyServerConfig = new NettyServerConfig();
    routeInfoManager = new RouteInfoManager();

    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);

    Field field = NamesrvController.class.getDeclaredField("routeInfoManager");
    field.setAccessible(true);
    field.set(namesrvController, routeInfoManager);
    defaultRequestProcessor = new DefaultRequestProcessor(namesrvController);

    registerRouteInfoManager();

    logger = mock(Logger.class);
    when(logger.isInfoEnabled()).thenReturn(false);
    setFinalStatic(DefaultRequestProcessor.class.getDeclaredField("log"), logger);
}
 
Example #22
Source File: RemotingServerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static RemotingServer createRemotingServer() throws InterruptedException {
    NettyServerConfig config = new NettyServerConfig();
    RemotingServer remotingServer = new NettyRemotingServer(config);
    remotingServer.registerProcessor(0, new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) {
            request.setRemark("Hi " + ctx.channel().remoteAddress());
            return request;
        }

        @Override
        public boolean rejectRequest() {
            return false;
        }
    }, Executors.newCachedThreadPool());

    remotingServer.start();

    return remotingServer;
}
 
Example #23
Source File: DLedgerRpcNettyService.java    From openmessaging-storage-dledger with Apache License 2.0 5 votes vote down vote up
public DLedgerRpcNettyService(DLedgerServer dLedgerServer) {
    this.dLedgerServer = dLedgerServer;
    this.memberState = dLedgerServer.getMemberState();
    NettyRequestProcessor protocolProcessor = new NettyRequestProcessor() {
        @Override
        public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws Exception {
            return DLedgerRpcNettyService.this.processRequest(ctx, request);
        }

        @Override public boolean rejectRequest() {
            return false;
        }
    };
    //start the remoting server
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(Integer.valueOf(memberState.getSelfAddr().split(":")[1]));
    this.remotingServer = new NettyRemotingServer(nettyServerConfig, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.METADATA.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.APPEND.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.GET.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.PULL.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.PUSH.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.VOTE.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.HEART_BEAT.getCode(), protocolProcessor, null);
    this.remotingServer.registerProcessor(DLedgerRequestCode.LEADERSHIP_TRANSFER.getCode(), protocolProcessor, null);

    //start the remoting client
    this.remotingClient = new NettyRemotingClient(new NettyClientConfig(), null);

}
 
Example #24
Source File: BrokerControllerTest.java    From rocketmq-all-4.1.0-incubating 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 #25
Source File: NamesrvControllerTest.java    From rocketmq-all-4.1.0-incubating 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 testRestart() throws Exception {
    for (int i = 0; i < RESTARTNUM; i++) {
        NamesrvController namesrvController = new NamesrvController(
            new NamesrvConfig(),
            new NettyServerConfig()
        );
        boolean initResult = namesrvController.initialize();
        assertThat(initResult).isEqualTo(true);
        namesrvController.start();
        namesrvController.shutdown();
    }
}
 
Example #26
Source File: NamesrvController.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public NamesrvController(NamesrvConfig namesrvConfig, NettyServerConfig nettyServerConfig) {
    this.namesrvConfig = namesrvConfig;
    this.nettyServerConfig = nettyServerConfig;
    this.kvConfigManager = new KVConfigManager(this);
    this.routeInfoManager = new RouteInfoManager();
    this.brokerHousekeepingService = new BrokerHousekeepingService(this);
    this.configuration = new Configuration(
        log,
        this.namesrvConfig, this.nettyServerConfig
    );
    this.configuration.setStorePathFromConfig(this.namesrvConfig, "configStorePath");
}
 
Example #27
Source File: BrokerControllerSlaveTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
     * broker 启动
     */
    @Test
    public void testBrokerRestart() throws Exception {
        System.setProperty("user.home", System.getProperty("user.home") + File.separator + "broker" + File.separator + "slave");

        // 设置版本号
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(20911);
        //
        final BrokerConfig brokerConfig = new BrokerConfig();
        brokerConfig.setBrokerName("broker-a");
        brokerConfig.setBrokerId(1L); // 1
        brokerConfig.setNamesrvAddr("127.0.0.1:9876");

        //
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        messageStoreConfig.setDeleteWhen("04");
        messageStoreConfig.setFileReservedTime(48);
        messageStoreConfig.setFlushDiskType(FlushDiskType.ASYNC_FLUSH);
        messageStoreConfig.setBrokerRole(BrokerRole.SLAVE);

        messageStoreConfig.setDuplicationEnable(false);

        messageStoreConfig.setHaListenPort(nettyServerConfig.getListenPort() + 1);

//        BrokerPathConfigHelper.setBrokerConfigPath("/Users/yunai/百度云同步盘/开发/Javascript/Story/incubator-rocketmq/conf/broker.conf");
        // broker 启动
        BrokerController brokerController = new BrokerController(//
                brokerConfig, //
                nettyServerConfig, //
                new NettyClientConfig(), //
                messageStoreConfig);
        brokerController.initialize();
        brokerController.start();
//        brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod()
        Thread.sleep(DateUtils.MILLIS_PER_DAY);
    }
 
Example #28
Source File: IntegrationTestBase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 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);
    brokerConfig.setEnablePropertyFilter(true);
    storeConfig.setStorePathRootDir(baseDir);
    storeConfig.setStorePathCommitLog(baseDir + SEP + "commitlog");
    storeConfig.setHaListenPort(8000 + random.nextInt(1000));
    storeConfig.setMapedFileSizeCommitLog(COMMIT_LOG_SIZE);
    storeConfig.setMaxIndexNum(INDEX_NUM);
    storeConfig.setMaxHashSlotNum(INDEX_NUM * 4);
    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 #29
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 #30
Source File: NamesrvController.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public NamesrvController(NamesrvConfig namesrvConfig, NettyServerConfig nettyServerConfig) {
    this.namesrvConfig = namesrvConfig;
    this.nettyServerConfig = nettyServerConfig;
    this.kvConfigManager = new KVConfigManager(this);
    this.routeInfoManager = new RouteInfoManager();
    this.brokerHousekeepingService = new BrokerHousekeepingService(this);
    this.configuration = new Configuration(
        log,
        this.namesrvConfig, this.nettyServerConfig
    );
    this.configuration.setStorePathFromConfig(this.namesrvConfig, "configStorePath");
}