Search in sources :

Example 6 with NettyRemotingServer

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

the class NamesrvController method initialize.

public boolean initialize() {
    // 加载KV配置
    this.kvConfigManager.load();
    // 初始化通信层
    // brokerHousekeepingService 接收Broker连接事件
    this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, this.brokerHousekeepingService);
    // 初始化固定线程池
    this.remotingExecutor = Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), new ThreadFactoryImpl("RemotingExecutorThread_"));
    // 注册接收到请求之后具体的处理
    this.registerProcessor();
    // 增加定时任务
    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            NamesrvController.this.routeInfoManager.scanNotActiveBroker();
        }
    }, 5, 10, // 每隔10s扫描broker,维护当前存活的Broker信息
    TimeUnit.SECONDS);
    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            NamesrvController.this.kvConfigManager.printAllPeriodically();
        }
    }, 1, 10, // 每隔10s打印KVConfig信息。
    TimeUnit.MINUTES);
    return true;
}
Also used : NettyRemotingServer(org.apache.rocketmq.remoting.netty.NettyRemotingServer) ThreadFactoryImpl(org.apache.rocketmq.common.ThreadFactoryImpl)

Example 7 with NettyRemotingServer

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

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 8 with NettyRemotingServer

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

the class FiltersrvController method initialize.

public boolean initialize() {
    MixAll.printObjectProperties(log, this.filtersrvConfig);
    this.remotingServer = new NettyRemotingServer(this.nettyServerConfig);
    this.remotingExecutor = Executors.newFixedThreadPool(nettyServerConfig.getServerWorkerThreads(), new ThreadFactoryImpl("RemotingExecutorThread_"));
    this.registerProcessor();
    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            FiltersrvController.this.registerFilterServerToBroker();
        }
    }, 3, 10, TimeUnit.SECONDS);
    this.defaultMQPullConsumer.setBrokerSuspendMaxTimeMillis(this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis() - 1000);
    this.defaultMQPullConsumer.setConsumerTimeoutMillisWhenSuspend(this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() - 1000);
    this.defaultMQPullConsumer.setNamesrvAddr(this.filtersrvConfig.getNamesrvAddr());
    this.defaultMQPullConsumer.setInstanceName(String.valueOf(UtilAll.getPid()));
    return true;
}
Also used : NettyRemotingServer(org.apache.rocketmq.remoting.netty.NettyRemotingServer) ThreadFactoryImpl(org.apache.rocketmq.common.ThreadFactoryImpl)

Aggregations

NettyRemotingServer (org.apache.rocketmq.remoting.netty.NettyRemotingServer)8 ThreadFactoryImpl (org.apache.rocketmq.common.ThreadFactoryImpl)6 NettyServerConfig (org.apache.rocketmq.remoting.netty.NettyServerConfig)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 IOException (java.io.IOException)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 CommitLogDispatcherCalcBitMap (org.apache.rocketmq.broker.filter.CommitLogDispatcherCalcBitMap)2 BrokerFixedThreadPoolExecutor (org.apache.rocketmq.broker.latency.BrokerFixedThreadPoolExecutor)2 MessageStorePluginContext (org.apache.rocketmq.broker.plugin.MessageStorePluginContext)2 NettyRequestProcessor (org.apache.rocketmq.remoting.netty.NettyRequestProcessor)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2 BrokerStats (org.apache.rocketmq.store.stats.BrokerStats)2