| 777 | } |
| 778 | |
| 779 | bool PublishKafka::createNewTopic(const std::shared_ptr<core::ProcessContext> &context, const std::string& topic_name) { |
| 780 | std::unique_ptr<rd_kafka_topic_conf_t, rd_kafka_topic_conf_deleter> topic_conf_{ rd_kafka_topic_conf_new() }; |
| 781 | if (topic_conf_ == nullptr) { |
| 782 | logger_->log_error("Failed to create rd_kafka_topic_conf_t object"); |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | rd_kafka_conf_res_t result; |
| 787 | std::string value; |
| 788 | std::array<char, 512U> errstr{}; |
| 789 | int64_t valInt; |
| 790 | std::string valueConf; |
| 791 | |
| 792 | value = ""; |
| 793 | if (context->getProperty(DeliveryGuarantee.getName(), value) && !value.empty()) { |
| 794 | /* |
| 795 | * Because of a previous error in this processor, the default value of this property was "DELIVERY_ONE_NODE". |
| 796 | * As this is not a valid value for "request.required.acks", the following rd_kafka_topic_conf_set call failed, |
| 797 | * but because of an another error, this failure was silently ignored, meaning that the the default value for |
| 798 | * "request.required.acks" did not change, and thus remained "-1". This means that having "DELIVERY_ONE_NODE" as |
| 799 | * the value of this property actually caused the processor to wait for delivery ACKs from ALL nodes, instead |
| 800 | * of just one. In order not to break configurations generated with earlier versions and keep the same behaviour |
| 801 | * as they had, we have to map "DELIVERY_ONE_NODE" to "-1" here. |
| 802 | */ |
| 803 | if (value == "DELIVERY_ONE_NODE") { |
| 804 | value = "-1"; |
| 805 | logger_->log_warn("Using DELIVERY_ONE_NODE as the Delivery Guarantee property is deprecated and is translated to -1 " |
| 806 | "(block until message is committed by all in sync replicas) for backwards compatibility. " |
| 807 | "If you want to wait for one acknowledgment use '1' as the property."); |
| 808 | } |
| 809 | result = rd_kafka_topic_conf_set(topic_conf_.get(), "request.required.acks", value.c_str(), errstr.data(), errstr.size()); |
| 810 | logger_->log_debug("PublishKafka: request.required.acks [%s]", value); |
| 811 | if (result != RD_KAFKA_CONF_OK) { |
| 812 | logger_->log_error("PublishKafka: configure request.required.acks error result [%s]", errstr.data()); |
| 813 | return false; |
| 814 | } |
| 815 | } |
| 816 | value = ""; |
| 817 | if (context->getProperty(RequestTimeOut.getName(), value) && !value.empty()) { |
| 818 | core::TimeUnit unit; |
| 819 | if (core::Property::StringToTime(value, valInt, unit) && |
| 820 | core::Property::ConvertTimeUnitToMS(valInt, unit, valInt)) { |
| 821 | valueConf = std::to_string(valInt); |
| 822 | result = rd_kafka_topic_conf_set(topic_conf_.get(), "request.timeout.ms", valueConf.c_str(), errstr.data(), errstr.size()); |
| 823 | logger_->log_debug("PublishKafka: request.timeout.ms [%s]", valueConf); |
| 824 | if (result != RD_KAFKA_CONF_OK) { |
| 825 | logger_->log_error("PublishKafka: configure request.timeout.ms error result [%s]", errstr.data()); |
| 826 | return false; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | value = ""; |
| 831 | if (context->getProperty(MessageTimeOut.getName(), value) && !value.empty()) { |
| 832 | core::TimeUnit unit; |
| 833 | if (core::Property::StringToTime(value, valInt, unit) && |
| 834 | core::Property::ConvertTimeUnitToMS(valInt, unit, valInt)) { |
| 835 | valueConf = std::to_string(valInt); |
| 836 | result = rd_kafka_topic_conf_set(topic_conf_.get(), "message.timeout.ms", valueConf.c_str(), errstr.data(), errstr.size()); |
nothing calls this directly
no test coverage detected