Search in sources :

Example 26 with NettyServerConfig

use of org.apache.rocketmq.remoting.netty.NettyServerConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BrokerControllerTest method testBrokerRestart.

/**
 * 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();
    }
}
Also used : MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BrokerConfig(org.apache.rocketmq.common.BrokerConfig) NettyClientConfig(org.apache.rocketmq.remoting.netty.NettyClientConfig) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) Test(org.junit.Test)

Example 27 with NettyServerConfig

use of org.apache.rocketmq.remoting.netty.NettyServerConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class FiltersrvStartup method createController.

public static FiltersrvController createController(String[] args) {
    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
    if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE)) {
        NettySystemConfig.socketSndbufSize = 65535;
    }
    if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE)) {
        NettySystemConfig.socketRcvbufSize = 1024;
    }
    try {
        Options options = ServerUtil.buildCommandlineOptions(new Options());
        final CommandLine commandLine = ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), new PosixParser());
        if (null == commandLine) {
            System.exit(-1);
            return null;
        }
        final FiltersrvConfig filtersrvConfig = new FiltersrvConfig();
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                Properties properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, filtersrvConfig);
                System.out.printf("load config properties file OK, " + file + "%n");
                in.close();
                String port = properties.getProperty("listenPort");
                if (port != null) {
                    filtersrvConfig.setConnectWhichBroker(String.format("127.0.0.1:%s", port));
                }
            }
        }
        nettyServerConfig.setListenPort(0);
        nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue());
        nettyServerConfig.setServerCallbackExecutorThreads(filtersrvConfig.getFsServerCallbackExecutorThreads());
        nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads());
        if (commandLine.hasOption('p')) {
            MixAll.printObjectProperties(null, filtersrvConfig);
            MixAll.printObjectProperties(null, nettyServerConfig);
            System.exit(0);
        }
        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig);
        if (null == filtersrvConfig.getRocketmqHome()) {
            System.out.printf("Please set the " + MixAll.ROCKETMQ_HOME_ENV + " variable in your environment to match the location of the RocketMQ installation%n");
            System.exit(-2);
        }
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(filtersrvConfig.getRocketmqHome() + "/conf/logback_filtersrv.xml");
        log = LoggerFactory.getLogger(LoggerName.FILTERSRV_LOGGER_NAME);
        final FiltersrvController controller = new FiltersrvController(filtersrvConfig, nettyServerConfig);
        boolean initResult = controller.initialize();
        if (!initResult) {
            controller.shutdown();
            System.exit(-3);
        }
        Runtime.getRuntime().addShutdownHook(new ShutdownHookThread(log, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                controller.shutdown();
                return null;
            }
        }));
        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return null;
}
Also used : Options(org.apache.commons.cli.Options) ShutdownHookThread(org.apache.rocketmq.srvutil.ShutdownHookThread) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PosixParser(org.apache.commons.cli.PosixParser) Properties(java.util.Properties) LoggerContext(ch.qos.logback.classic.LoggerContext) FileInputStream(java.io.FileInputStream) Callable(java.util.concurrent.Callable) CommandLine(org.apache.commons.cli.CommandLine) BufferedInputStream(java.io.BufferedInputStream) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig)

Example 28 with NettyServerConfig

use of org.apache.rocketmq.remoting.netty.NettyServerConfig in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AbstractTestCase method startNamesrv.

/**
 * Start rocketmq name server
 * @throws Exception
 */
private static void startNamesrv() throws Exception {
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(9876);
    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);
    boolean initResult = namesrvController.initialize();
    if (!initResult) {
        namesrvController.shutdown();
        throw new Exception();
    }
    namesrvController.start();
}
Also used : NamesrvConfig(org.apache.rocketmq.common.namesrv.NamesrvConfig) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) NamesrvController(org.apache.rocketmq.namesrv.NamesrvController) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 29 with NettyServerConfig

use of org.apache.rocketmq.remoting.netty.NettyServerConfig in project rocketmq-externals by apache.

the class RocketMQSourceTest method startNamesrv.

private static void startNamesrv() throws Exception {
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(9876);
    namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig);
    boolean initResult = namesrvController.initialize();
    if (!initResult) {
        namesrvController.shutdown();
        throw new Exception();
    }
    namesrvController.start();
}
Also used : NamesrvConfig(org.apache.rocketmq.common.namesrv.NamesrvConfig) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) NamesrvController(org.apache.rocketmq.namesrv.NamesrvController) MQClientException(org.apache.rocketmq.client.exception.MQClientException) EventDeliveryException(org.apache.flume.EventDeliveryException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 30 with NettyServerConfig

use of org.apache.rocketmq.remoting.netty.NettyServerConfig in project ignite by apache.

the class TestRocketMQServer method startBroker.

/**
 * Starts a test broker.
 *
 * @throws Exception If fails.
 */
private void startBroker() throws Exception {
    BrokerConfig brokerCfg = new BrokerConfig();
    NettyServerConfig nettySrvCfg = new NettyServerConfig();
    MessageStoreConfig storeCfg = new MessageStoreConfig();
    brokerCfg.setBrokerName(TEST_BROKER);
    brokerCfg.setBrokerClusterName(TEST_CLUSTER);
    brokerCfg.setBrokerIP1(TEST_IP);
    brokerCfg.setNamesrvAddr(TEST_IP + ":" + NAME_SERVER_PORT);
    storeCfg.setStorePathRootDir(System.getProperty("java.io.tmpdir") + separator + "store-" + UUID.randomUUID());
    storeCfg.setStorePathCommitLog(System.getProperty("java.io.tmpdir") + separator + "commitlog");
    storeCfg.setHaListenPort(HA_PORT);
    nettySrvCfg.setListenPort(BROKER_PORT);
    broker = new BrokerController(brokerCfg, nettySrvCfg, new NettyClientConfig(), storeCfg);
    broker.initialize();
    broker.start();
    log.info("Started broker [" + TEST_BROKER + "] at " + BROKER_PORT);
}
Also used : MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BrokerConfig(org.apache.rocketmq.common.BrokerConfig) NettyClientConfig(org.apache.rocketmq.remoting.netty.NettyClientConfig) BrokerController(org.apache.rocketmq.broker.BrokerController) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig)

Aggregations

NettyServerConfig (org.apache.rocketmq.remoting.netty.NettyServerConfig)46 NamesrvConfig (org.apache.rocketmq.common.namesrv.NamesrvConfig)23 NamesrvController (org.apache.rocketmq.namesrv.NamesrvController)20 MQClientException (org.apache.rocketmq.client.exception.MQClientException)17 BrokerConfig (org.apache.rocketmq.common.BrokerConfig)17 NettyClientConfig (org.apache.rocketmq.remoting.netty.NettyClientConfig)17 MessageStoreConfig (org.apache.rocketmq.store.config.MessageStoreConfig)17 BrokerController (org.apache.rocketmq.broker.BrokerController)13 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)8 LoggerContext (ch.qos.logback.classic.LoggerContext)6 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)6 BufferedInputStream (java.io.BufferedInputStream)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Properties (java.util.Properties)6 Options (org.apache.commons.cli.Options)6 PosixParser (org.apache.commons.cli.PosixParser)6