All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.godmao.mqbroker.BrokerInitializer Maven / Gradle / Ivy

There is a newer version: 0.2.7.RELEASE
Show newest version
package com.godmao.mqbroker;

import com.godmao.mqbroker.handler.*;
import com.godmao.netty.handler.DefaultLengthFieldDecoderHandler;
import com.godmao.netty.handler.DefaultLengthFieldEncoderHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

class BrokerInitializer extends ChannelInitializer {

    private final Broker connect;

    public BrokerInitializer(Broker connect) {
        this.connect = connect;
    }

    @Override
    protected void initChannel(Channel ch) {
        ChannelPipeline pipeline = ch.pipeline();
        int index = 0;
//        // 打印包数据
//        pipeline.addLast("logging-" + ++index, new LoggingHandler());
        // 空闲状态检测器
        pipeline.addLast("idlestate-" + ++index, new IdleStateHandler(120, 0, 0, TimeUnit.SECONDS));
        // 事件触发处理器
        pipeline.addLast("heartbeat-" + ++index, EventTriggeredHandler.INSTANCE);
        // 拆包器 只能接收1M
        pipeline.addLast("unpacker-" + ++index, new DefaultLengthFieldDecoderHandler());
        // 粘包器
        pipeline.addLast("prepender-" + ++index, new DefaultLengthFieldEncoderHandler());
        // 过滤器
        pipeline.addLast("filter-" + ++index, FilterHandler.INSTANCE);
        // 解码器
        pipeline.addLast("decode-" + ++index, BrokerDecoderHandler.INSTANCE);
        // 编码器 -服务绑定
        pipeline.addLast("encode-" + ++index, BindMessageEncoderHandler.INSTANCE);
        // 编码器 -同步主题消息处理器
        pipeline.addLast("encode-" + ++index, TopicSyncMessageEncoderHandler.INSTANCE);
        // 编码器 -心跳
        pipeline.addLast("encode-" + ++index, HeartbeatMessageEncoderHandler.INSTANCE);
        // 编码器 -服务消息转发 -单服务
        pipeline.addLast("encode-" + ++index, SingleMessageEncoderHandler.INSTANCE);
        // 编码器 -服务消息转发 -多服务
        pipeline.addLast("encode-" + ++index, MultipleMessageEncoderHandler.INSTANCE);
        // 业务处理器
        pipeline.addLast("servic" + ++index, new MultipleMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new SingleMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new HeartbeatMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new BindMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new TopicSubscribeCancelMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new TopicSubscribeMessageHandler(connect));
        pipeline.addLast("servic" + ++index, new BrokerBaseHandler(connect));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy