5.3确认消息大小

首先我们先来看一下步骤四,判断一条消息的大小,就是这里

  /**
             * 步骤四:
             * 确认一下消息的大小是否超过了最大值
             * kafkaproducer初始化的时候,指定了一个参数,代表的是producer这最大能发送的是一条消息能有多大
             * 默认最大是1M,生产上会去修改
             *
             */
            ensureValidRecordSize(serializedSize);

跟进去

/**
     * Validate that the record size isn't too large
     */
    private void ensureValidRecordSize(int size) {
        //如果一条消息的大小超过了1M,就会报错
        if (size > this.maxRequestSize)
            //自定义异常
            throw new RecordTooLargeException("The message is " + size +
                                              " bytes when serialized which is larger than the maximum request size you have configured with the " +
                                              ProducerConfig.MAX_REQUEST_SIZE_CONFIG +
                                              " configuration.");
        //如果一条消息的大小超过了32M(缓存的大小)也会报错
        if (size > this.totalMemorySize)
            throw new RecordTooLargeException("The message is " + size +
                                              " bytes when serialized which is larger than the total memory buffer you have configured with the " +
                                              ProducerConfig.BUFFER_MEMORY_CONFIG +
                                              " configuration.");
    }

这里比较简单

步骤5,6也比较简单容易理解,有兴趣可以看一下

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值