Search in sources :

Example 6 with NettyClientConfig

use of org.apache.rocketmq.remoting.netty.NettyClientConfig in project rocketmq by apache.

the class TlsTest method setUp.

@Before
public void setUp() throws InterruptedException {
    tlsMode = TlsMode.ENFORCING;
    tlsTestModeEnable = false;
    tlsServerNeedClientAuth = "require";
    tlsServerKeyPath = getCertsPath("server.key");
    tlsServerCertPath = getCertsPath("server.pem");
    tlsServerAuthClient = true;
    tlsServerTrustCertPath = getCertsPath("ca.pem");
    tlsClientKeyPath = getCertsPath("client.key");
    tlsClientCertPath = getCertsPath("client.pem");
    tlsClientAuthServer = true;
    tlsClientTrustCertPath = getCertsPath("ca.pem");
    tlsClientKeyPassword = "1234";
    tlsServerKeyPassword = "";
    NettyClientConfig clientConfig = new NettyClientConfig();
    clientConfig.setUseTLS(true);
    if ("serverRejectsUntrustedClientCert".equals(name.getMethodName())) {
        // Create a client. Its credentials come from a CA that the server does not trust. The client
        // trusts both test CAs to ensure the handshake failure is due to the server rejecting the client's cert.
        tlsClientKeyPath = getCertsPath("badClient.key");
        tlsClientCertPath = getCertsPath("badClient.pem");
    } else if ("serverAcceptsUntrustedClientCert".equals(name.getMethodName())) {
        tlsClientKeyPath = getCertsPath("badClient.key");
        tlsClientCertPath = getCertsPath("badClient.pem");
        tlsServerAuthClient = false;
    } else if ("noClientAuthFailure".equals(name.getMethodName())) {
        // Clear the client cert config to ensure produce the handshake error
        tlsClientKeyPath = "";
        tlsClientCertPath = "";
    } else if ("clientRejectsUntrustedServerCert".equals(name.getMethodName())) {
        tlsServerKeyPath = getCertsPath("badServer.key");
        tlsServerCertPath = getCertsPath("badServer.pem");
    } else if ("clientAcceptsUntrustedServerCert".equals(name.getMethodName())) {
        tlsServerKeyPath = getCertsPath("badServer.key");
        tlsServerCertPath = getCertsPath("badServer.pem");
        tlsClientAuthServer = false;
    } else if ("serverNotNeedClientAuth".equals(name.getMethodName())) {
        tlsServerNeedClientAuth = "none";
        tlsClientKeyPath = "";
        tlsClientCertPath = "";
    } else if ("serverWantClientAuth".equals(name.getMethodName())) {
        tlsServerNeedClientAuth = "optional";
    } else if ("serverWantClientAuth_ButClientNoCert".equals(name.getMethodName())) {
        tlsServerNeedClientAuth = "optional";
        tlsClientKeyPath = "";
        tlsClientCertPath = "";
    } else if ("serverAcceptsUnAuthClient".equals(name.getMethodName())) {
        tlsMode = TlsMode.PERMISSIVE;
        tlsClientKeyPath = "";
        tlsClientCertPath = "";
        clientConfig.setUseTLS(false);
    } else if ("serverRejectsSSLClient".equals(name.getMethodName())) {
        tlsMode = TlsMode.DISABLED;
    }
    remotingServer = RemotingServerTest.createRemotingServer();
    remotingClient = RemotingServerTest.createRemotingClient(clientConfig);
}
Also used : NettyClientConfig(org.apache.rocketmq.remoting.netty.NettyClientConfig) Before(org.junit.Before)

Example 7 with NettyClientConfig

use of org.apache.rocketmq.remoting.netty.NettyClientConfig in project rocketmq by apache.

the class BrokerStartup method createBrokerController.

public static BrokerController createBrokerController(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 = 131072;
    }
    if (null == System.getProperty(NettySystemConfig.COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE)) {
        NettySystemConfig.socketRcvbufSize = 131072;
    }
    try {
        // PackageConflictDetect.detectFastjson();
        Options options = ServerUtil.buildCommandlineOptions(new Options());
        commandLine = ServerUtil.parseCmdLine("mqbroker", args, buildCommandlineOptions(options), new PosixParser());
        if (null == commandLine) {
            System.exit(-1);
        }
        final BrokerConfig brokerConfig = new BrokerConfig();
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        final NettyClientConfig nettyClientConfig = new NettyClientConfig();
        nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TLS_ENABLE, String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING))));
        nettyServerConfig.setListenPort(10911);
        final MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
        if (BrokerRole.SLAVE == messageStoreConfig.getBrokerRole()) {
            int ratio = messageStoreConfig.getAccessMessageInMemoryMaxRatio() - 10;
            messageStoreConfig.setAccessMessageInMemoryMaxRatio(ratio);
        }
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                configFile = file;
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                properties2SystemEnv(properties);
                MixAll.properties2Object(properties, brokerConfig);
                MixAll.properties2Object(properties, nettyServerConfig);
                MixAll.properties2Object(properties, nettyClientConfig);
                MixAll.properties2Object(properties, messageStoreConfig);
                BrokerPathConfigHelper.setBrokerConfigPath(file);
                in.close();
            }
        }
        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), brokerConfig);
        if (null == brokerConfig.getRocketmqHome()) {
            System.out.printf("Please set the " + MixAll.ROCKETMQ_HOME_ENV + " variable in your environment to match the location of the RocketMQ installation");
            System.exit(-2);
        }
        String namesrvAddr = brokerConfig.getNamesrvAddr();
        if (null != namesrvAddr) {
            try {
                String[] addrArray = namesrvAddr.split(";");
                for (String addr : addrArray) {
                    RemotingUtil.string2SocketAddress(addr);
                }
            } catch (Exception e) {
                System.out.printf("The Name Server Address[%s] illegal, please set it as follows, \"127.0.0.1:9876;192.168.0.1:9876\"%n", namesrvAddr);
                System.exit(-3);
            }
        }
        switch(messageStoreConfig.getBrokerRole()) {
            case ASYNC_MASTER:
            case SYNC_MASTER:
                brokerConfig.setBrokerId(MixAll.MASTER_ID);
                break;
            case SLAVE:
                if (brokerConfig.getBrokerId() <= 0) {
                    System.out.printf("Slave's brokerId must be > 0");
                    System.exit(-3);
                }
                break;
            default:
                break;
        }
        messageStoreConfig.setHaListenPort(nettyServerConfig.getListenPort() + 1);
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(brokerConfig.getRocketmqHome() + "/conf/logback_broker.xml");
        if (commandLine.hasOption('p')) {
            Logger console = LoggerFactory.getLogger(LoggerName.BROKER_CONSOLE_NAME);
            MixAll.printObjectProperties(console, brokerConfig);
            MixAll.printObjectProperties(console, nettyServerConfig);
            MixAll.printObjectProperties(console, nettyClientConfig);
            MixAll.printObjectProperties(console, messageStoreConfig);
            System.exit(0);
        } else if (commandLine.hasOption('m')) {
            Logger console = LoggerFactory.getLogger(LoggerName.BROKER_CONSOLE_NAME);
            MixAll.printObjectProperties(console, brokerConfig, true);
            MixAll.printObjectProperties(console, nettyServerConfig, true);
            MixAll.printObjectProperties(console, nettyClientConfig, true);
            MixAll.printObjectProperties(console, messageStoreConfig, true);
            System.exit(0);
        }
        log = LoggerFactory.getLogger(LoggerName.BROKER_LOGGER_NAME);
        MixAll.printObjectProperties(log, brokerConfig);
        MixAll.printObjectProperties(log, nettyServerConfig);
        MixAll.printObjectProperties(log, nettyClientConfig);
        MixAll.printObjectProperties(log, messageStoreConfig);
        final BrokerController controller = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, messageStoreConfig);
        // remember all configs to prevent discard
        controller.getConfiguration().registerConfig(properties);
        boolean initResult = controller.initialize();
        if (!initResult) {
            controller.shutdown();
            System.exit(-3);
        }
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            private volatile boolean hasShutdown = false;

            private AtomicInteger shutdownTimes = new AtomicInteger(0);

            @Override
            public void run() {
                synchronized (this) {
                    log.info("Shutdown hook was invoked, {}", this.shutdownTimes.incrementAndGet());
                    if (!this.hasShutdown) {
                        this.hasShutdown = true;
                        long beginTime = System.currentTimeMillis();
                        controller.shutdown();
                        long consumingTimeTotal = System.currentTimeMillis() - beginTime;
                        log.info("Shutdown hook over, consuming total time(ms): {}", consumingTimeTotal);
                    }
                }
            }
        }, "ShutdownHook"));
        return controller;
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return null;
}
Also used : Options(org.apache.commons.cli.Options) BrokerConfig(org.apache.rocketmq.common.BrokerConfig) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PosixParser(org.apache.commons.cli.PosixParser) Properties(java.util.Properties) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) FileInputStream(java.io.FileInputStream) MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BufferedInputStream(java.io.BufferedInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NettyClientConfig(org.apache.rocketmq.remoting.netty.NettyClientConfig) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig)

Example 8 with NettyClientConfig

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

the class IntegrationTestBase method createAndStartBroker.

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;
}
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)

Example 9 with NettyClientConfig

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

the class RocketMQServerMock method startBroker.

private void startBroker() throws Exception {
    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setNamesrvAddr(nameserverAddr);
    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("Broker init failure!");
    }
    brokerController.start();
}
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) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 10 with NettyClientConfig

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

the class AbstractTestCase method startBroker.

/**
 * 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();
}
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) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Aggregations

NettyClientConfig (org.apache.rocketmq.remoting.netty.NettyClientConfig)15 BrokerConfig (org.apache.rocketmq.common.BrokerConfig)13 NettyServerConfig (org.apache.rocketmq.remoting.netty.NettyServerConfig)13 MessageStoreConfig (org.apache.rocketmq.store.config.MessageStoreConfig)13 BrokerController (org.apache.rocketmq.broker.BrokerController)9 MQClientException (org.apache.rocketmq.client.exception.MQClientException)5 LoggerContext (ch.qos.logback.classic.LoggerContext)2 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Options (org.apache.commons.cli.Options)2 PosixParser (org.apache.commons.cli.PosixParser)2 EventDeliveryException (org.apache.flume.EventDeliveryException)2 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2