Flink踩坑之DEBUG日志配置与Sink到Mysql

Flink日志配置

log4j,debug需要落盘的话,代码中配置没用,需要在flink/conf/log4j.properties进行修改
代码中使用;

Logger logger = LoggerFactory.getLogger(XXXXX.class);
logger.debug("This message contains {} placeholders. {}", "origin", JSON.toJSONString(xxxx));

自用如下:

#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
# limitations under the License.
################################################################################
# This affects logging for both user code and Flink
log4j.rootLogger=DEBUG, file

# Uncomment this if you want to _only_ change Flink's logging
#log4j.logger.org.apache.flink=INFO
# The following lines keep the log level of common libraries/connectors on
# log level INFO. The root logger does not override this. You have to manually
# change the log levels here.
log4j.logger.akka=INFO
log4j.logger.org.apache.kafka=INFO
log4j.logger.org.apache.hadoop=INFO
log4j.logger.org.apache.zookeeper=INFO
# Log all infos in the given file

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.file=/opt/frame/debuglogs/flink.log
log4j.appender.file.append=true
log4j.appender.file.Threshold =DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
# Suppress the irrelevant (wrong) warnings from the Netty channel handler
log4j.logger.org.apache.flink.shaded.akka.org.jboss.netty.channel.DefaultChannelPipeline=DEBUG, file

Sink到Mysql

笔者使用德鲁伊+mybatis结合sink到mysql中的时候,发现数据不对,达不到需求,不确定原因是什么,有大佬知道也可以告知下。需求是:只保留第一批数据,第二批数据不希望插入成功。然而第一批数据写入不成功,第二批数据数据成功(存在主键冲突,不知道是否是框架给优化掉了)。最终采用手写的方式插入成功,没问题。
Sink方法如下:

new RichSinkFunction<List<OrderAndTask>>() {
                    PreparedStatement ps;
                    private Connection connection;
                    @Override
                    public void open(Configuration parameters) throws Exception {
                        connection = MysqlUtils.getSinkMysqlConnection();
                        String sql = "insert ignore into order_task_relevance(id, task_id, create_day) values(?, ?, ?);";
                        ps = this.connection.prepareStatement(sql);
                    }



                    @Override
                    public void invoke(List<OrderAndTask> value, Context context) throws Exception {
                        for (OrderAndTask v : value) {
                            ps.setString(1,v.getId());
                            ps.setString(2,v.getTaskId());
                            ps.setString(3,v.getCreateDay());
                            ps.executeUpdate();
                        }
                    }

                    @Override
                    public void close() throws Exception {
                        //关闭连接和释放资源
                        if (connection != null) {
                            connection.close();
                        }
                        if (ps != null) {
                            ps.close();
                        }
                    }
                }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值