Search in sources :

Example 1 with NettyServerConfig

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

the class TestRocketMQServer method startNameServer.

/**
 * Starts a test nameserver.
 *
 * @throws Exception If fails.
 */
private void startNameServer() throws Exception {
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(System.getProperty("java.io.tmpdir") + separator + "namesrv" + separator + "kvConfig.json");
    nameServerNettyServerConfig.setListenPort(NAME_SERVER_PORT);
    nameSrv = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    nameSrv.initialize();
    nameSrv.start();
    log.info("Started nameserver at " + NAME_SERVER_PORT);
}
Also used : NamesrvConfig(org.apache.rocketmq.common.namesrv.NamesrvConfig) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) NamesrvController(org.apache.rocketmq.namesrv.NamesrvController)

Example 2 with NettyServerConfig

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

the class RocketMQSourceTest method startBroker.

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) EventDeliveryException(org.apache.flume.EventDeliveryException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with NettyServerConfig

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

the class RocketMQServerMock method startNamesrv.

private 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("Namesvr init failure!");
    }
    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 4 with NettyServerConfig

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

the class RequestHeader method createRemotingServer.

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;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) NettyRemotingServer(org.apache.rocketmq.remoting.netty.NettyRemotingServer) NettyRemotingServer(org.apache.rocketmq.remoting.netty.NettyRemotingServer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) NettyRequestProcessor(org.apache.rocketmq.remoting.netty.NettyRequestProcessor)

Example 5 with NettyServerConfig

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

the class BrokerController method initialize.

public boolean initialize() throws CloneNotSupportedException {
    boolean result = this.topicConfigManager.load();
    result = result && this.consumerOffsetManager.load();
    result = result && this.subscriptionGroupManager.load();
    result = result && this.consumerFilterManager.load();
    if (result) {
        try {
            this.messageStore = new DefaultMessageStore(this.messageStoreConfig, this.brokerStatsManager, this.messageArrivingListener, this.brokerConfig);
            this.brokerStats = new BrokerStats((DefaultMessageStore) this.messageStore);
            // load plugin
            MessageStorePluginContext context = new MessageStorePluginContext(messageStoreConfig, brokerStatsManager, messageArrivingListener, brokerConfig);
            this.messageStore = MessageStoreFactory.build(context, this.messageStore);
            this.messageStore.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(this.brokerConfig, this.consumerFilterManager));
        } catch (IOException e) {
            result = false;
            log.error("Failed to initialize", e);
        }
    }
    result = result && this.messageStore.load();
    if (result) {
        this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, this.clientHousekeepingService);
        NettyServerConfig fastConfig = (NettyServerConfig) this.nettyServerConfig.clone();
        fastConfig.setListenPort(nettyServerConfig.getListenPort() - 2);
        this.fastRemotingServer = new NettyRemotingServer(fastConfig, this.clientHousekeepingService);
        this.sendMessageExecutor = new BrokerFixedThreadPoolExecutor(this.brokerConfig.getSendMessageThreadPoolNums(), this.brokerConfig.getSendMessageThreadPoolNums(), 1000 * 60, TimeUnit.MILLISECONDS, this.sendThreadPoolQueue, new ThreadFactoryImpl("SendMessageThread_"));
        this.pullMessageExecutor = new BrokerFixedThreadPoolExecutor(this.brokerConfig.getPullMessageThreadPoolNums(), this.brokerConfig.getPullMessageThreadPoolNums(), 1000 * 60, TimeUnit.MILLISECONDS, this.pullThreadPoolQueue, new ThreadFactoryImpl("PullMessageThread_"));
        this.queryMessageExecutor = new BrokerFixedThreadPoolExecutor(this.brokerConfig.getQueryMessageThreadPoolNums(), this.brokerConfig.getQueryMessageThreadPoolNums(), 1000 * 60, TimeUnit.MILLISECONDS, this.queryThreadPoolQueue, new ThreadFactoryImpl("QueryMessageThread_"));
        this.adminBrokerExecutor = Executors.newFixedThreadPool(this.brokerConfig.getAdminBrokerThreadPoolNums(), new ThreadFactoryImpl("AdminBrokerThread_"));
        this.clientManageExecutor = new ThreadPoolExecutor(this.brokerConfig.getClientManageThreadPoolNums(), this.brokerConfig.getClientManageThreadPoolNums(), 1000 * 60, TimeUnit.MILLISECONDS, this.clientManagerThreadPoolQueue, new ThreadFactoryImpl("ClientManageThread_"));
        this.consumerManageExecutor = Executors.newFixedThreadPool(this.brokerConfig.getConsumerManageThreadPoolNums(), new ThreadFactoryImpl("ConsumerManageThread_"));
        this.registerProcessor();
        final long initialDelay = UtilAll.computNextMorningTimeMillis() - System.currentTimeMillis();
        final long period = 1000 * 60 * 60 * 24;
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerController.this.getBrokerStats().record();
                } catch (Throwable e) {
                    log.error("schedule record error.", e);
                }
            }
        }, initialDelay, period, TimeUnit.MILLISECONDS);
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerController.this.consumerOffsetManager.persist();
                } catch (Throwable e) {
                    log.error("schedule persist consumerOffset error.", e);
                }
            }
        }, 1000 * 10, this.brokerConfig.getFlushConsumerOffsetInterval(), TimeUnit.MILLISECONDS);
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerController.this.consumerFilterManager.persist();
                } catch (Throwable e) {
                    log.error("schedule persist consumer filter error.", e);
                }
            }
        }, 1000 * 10, 1000 * 10, TimeUnit.MILLISECONDS);
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerController.this.protectBroker();
                } catch (Throwable e) {
                    log.error("protectBroker error.", e);
                }
            }
        }, 3, 3, TimeUnit.MINUTES);
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerController.this.printWaterMark();
                } catch (Throwable e) {
                    log.error("printWaterMark error.", e);
                }
            }
        }, 10, 1, TimeUnit.SECONDS);
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                try {
                    log.info("dispatch behind commit log {} bytes", BrokerController.this.getMessageStore().dispatchBehindBytes());
                } catch (Throwable e) {
                    log.error("schedule dispatchBehindBytes error.", e);
                }
            }
        }, 1000 * 10, 1000 * 60, TimeUnit.MILLISECONDS);
        if (this.brokerConfig.getNamesrvAddr() != null) {
            this.brokerOuterAPI.updateNameServerAddressList(this.brokerConfig.getNamesrvAddr());
            log.info("Set user specified name server address: {}", this.brokerConfig.getNamesrvAddr());
        } else if (this.brokerConfig.isFetchNamesrvAddrByAddressServer()) {
            this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

                @Override
                public void run() {
                    try {
                        BrokerController.this.brokerOuterAPI.fetchNameServerAddr();
                    } catch (Throwable e) {
                        log.error("ScheduledTask fetchNameServerAddr exception", e);
                    }
                }
            }, 1000 * 10, 1000 * 60 * 2, TimeUnit.MILLISECONDS);
        }
        if (BrokerRole.SLAVE == this.messageStoreConfig.getBrokerRole()) {
            if (this.messageStoreConfig.getHaMasterAddress() != null && this.messageStoreConfig.getHaMasterAddress().length() >= 6) {
                this.messageStore.updateHaMasterAddress(this.messageStoreConfig.getHaMasterAddress());
                this.updateMasterHAServerAddrPeriodically = false;
            } else {
                this.updateMasterHAServerAddrPeriodically = true;
            }
            this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

                @Override
                public void run() {
                    try {
                        BrokerController.this.slaveSynchronize.syncAll();
                    } catch (Throwable e) {
                        log.error("ScheduledTask syncAll slave exception", e);
                    }
                }
            }, 1000 * 10, 1000 * 60, TimeUnit.MILLISECONDS);
        } else {
            this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

                @Override
                public void run() {
                    try {
                        BrokerController.this.printMasterAndSlaveDiff();
                    } catch (Throwable e) {
                        log.error("schedule printMasterAndSlaveDiff error.", e);
                    }
                }
            }, 1000 * 10, 1000 * 60, TimeUnit.MILLISECONDS);
        }
    }
    return result;
}
Also used : NettyRemotingServer(org.apache.rocketmq.remoting.netty.NettyRemotingServer) ThreadFactoryImpl(org.apache.rocketmq.common.ThreadFactoryImpl) BrokerFixedThreadPoolExecutor(org.apache.rocketmq.broker.latency.BrokerFixedThreadPoolExecutor) CommitLogDispatcherCalcBitMap(org.apache.rocketmq.broker.filter.CommitLogDispatcherCalcBitMap) IOException(java.io.IOException) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) BrokerFixedThreadPoolExecutor(org.apache.rocketmq.broker.latency.BrokerFixedThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BrokerStats(org.apache.rocketmq.store.stats.BrokerStats) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) MessageStorePluginContext(org.apache.rocketmq.broker.plugin.MessageStorePluginContext)

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