聊聊rocketmq的RemotingException

本文主要研究一下rocketmq的RemotingException

RemotingException

org/apache/rocketmq/remoting/exception/RemotingException.java

public class RemotingException extends Exception {
    private static final long serialVersionUID = -5690687334570505110L;

    public RemotingException(String message) {
        super(message);
    }

    public RemotingException(String message, Throwable cause) {
        super(message, cause);
    }
}
复制代码
  • 继承自checked exception,底下有RemotingCommandException、RemotingConnectException、RemotingSendRequestException、RemotingTimeoutException、RemotingTooMuchRequestException

RemotingCommandException

org/apache/rocketmq/remoting/exception/RemotingCommandException.java

public class RemotingCommandException extends RemotingException {
    private static final long serialVersionUID = -6061365915274953096L;

    public RemotingCommandException(String message) {
        super(message, null);
    }

    public RemotingCommandException(String message, Throwable cause) {
        super(message, cause);
    }
}
复制代码
  • RemotingCommand解码decodeCommandCustomHeader时可能抛出的异常

RemotingConnectException

org/apache/rocketmq/remoting/exception/RemotingConnectException.java

public class RemotingConnectException extends RemotingException {
    private static final long serialVersionUID = -5565366231695911316L;

    public RemotingConnectException(String addr) {
        this(addr, null);
    }

    public RemotingConnectException(String addr, Throwable cause) {
        super("connect to <" + addr + "> failed", cause);
    }
}
复制代码
  • NettyRemotingClient在channel出现问题的时候会抛出RemotingConnectException

RemotingSendRequestException

org/apache/rocketmq/remoting/exception/RemotingSendRequestException.java

public class RemotingSendRequestException extends RemotingException {
    private static final long serialVersionUID = 5391285827332471674L;

    public RemotingSendRequestException(String addr) {
        this(addr, null);
    }

    public RemotingSendRequestException(String addr, Throwable cause) {
        super("send request to <" + addr + "> failed", cause);
    }
}
复制代码
  • NettyRemotingClient在发送请求失败的时候,会抛出RemotingSendRequestException

RemotingTimeoutException

org/apache/rocketmq/remoting/exception/RemotingTimeoutException.java

public class RemotingTimeoutException extends RemotingException {

    private static final long serialVersionUID = 4106899185095245979L;

    public RemotingTimeoutException(String message) {
        super(message);
    }

    public RemotingTimeoutException(String addr, long timeoutMillis) {
        this(addr, timeoutMillis, null);
    }

    public RemotingTimeoutException(String addr, long timeoutMillis, Throwable cause) {
        super("wait response on the channel <" + addr + "> timeout, " + timeoutMillis + "(ms)", cause);
    }
}
复制代码
  • NettyRemotingClient在发送请求时,如果返回回来的RemotingCommand为null,但是发送请求成功,则抛出RemotingTimeoutException

RemotingTooMuchRequestException

org/apache/rocketmq/remoting/exception/RemotingTooMuchRequestException.java

public class RemotingTooMuchRequestException extends RemotingException {
    private static final long serialVersionUID = 4326919581254519654L;

    public RemotingTooMuchRequestException(String message) {
        super(message);
    }
}
复制代码
  • NettyRemotingAbstract在执行请求之前要进行流控,如果获取不到信号量,则区分是否是超时,如果是无timeout获取信号量也没获取到,则表示RemotingTooMuchRequestException

小结

rocketmq的remoting模块的异常采用的是checked exception,定义了根异常RemotingException,底下有几个异常分别为RemotingCommandException、RemotingConnectException、RemotingSendRequestException、RemotingTimeoutException、RemotingTooMuchRequestException。

doc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值