hunyadi-dev commented on a change in pull request #940: URL: https://github.com/apache/nifi-minifi-cpp/pull/940#discussion_r534936351
########## File path: extensions/librdkafka/rdkafka_utils.h ########## @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +#pragma once + +#include <algorithm> +#include <chrono> +#include <memory> +#include <string> +#include <thread> +#include <utility> +#include <vector> + +#include "core/logging/LoggerConfiguration.h" +#include "utils/OptionalUtils.h" +#include "rdkafka.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace utils { + +enum class KafkaEncoding { + UTF8, + HEX +}; + +struct rd_kafka_conf_deleter { + void operator()(rd_kafka_conf_t* ptr) const noexcept { rd_kafka_conf_destroy(ptr); } +}; + +struct rd_kafka_producer_deleter { + void operator()(rd_kafka_t* ptr) const noexcept { + rd_kafka_resp_err_t flush_ret = rd_kafka_flush(ptr, 10000 /* ms */); // Matching the wait time of KafkaConnection.cpp + // If concerned, we could log potential errors here: + // if (RD_KAFKA_RESP_ERR__TIMED_OUT == flush_ret) { + // std::cerr << "Deleting producer failed: time-out while trying to flush" << std::endl; + // } Review comment: I think as the error-enum returned is not obvious this is nice to have here. Another point is that one might not immediately think this could be a point of failure. I would have had this code in as debug log, but that would mean that any deleter would have to have an access to a logger. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
