Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions kafka/src/kafka/producer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <userver/kafka/producer.hpp>

#include <userver/engine/task/cancel.hpp>
#include <userver/formats/json/value_builder.hpp>
#include <userver/formats/serialize/common_containers.hpp>
#include <userver/kafka/impl/configuration.hpp>
#include <userver/kafka/impl/stats.hpp>
#include <userver/logging/log.hpp>
#include <userver/testsuite/testpoint.hpp>
#include <userver/tracing/span.hpp>
#include <userver/utils/async.hpp>
Expand Down Expand Up @@ -136,6 +138,14 @@ void Producer::Send(
std::optional<std::uint32_t> partition,
HeaderViews headers
) const {
engine::TaskCancellationBlocker blocker;

if (engine::current_task::IsCancelRequested())
{
LOG_WARNING("Task cancellation requested. Skip sending message");
return;
}

utils::Async(producer_task_processor_, "producer_send", [this, topic_name, key, message, partition, &headers] {
SendImpl(topic_name, key, message, partition, impl::HeadersHolder{headers});
}).Get();
Expand All @@ -148,6 +158,14 @@ void Producer::SendWrapper(
std::optional<std::uint32_t> partition,
HeaderViews headers
) const {
engine::TaskCancellationBlocker blocker;

if (engine::current_task::IsCancelRequested())
{
LOG_WARNING("Task cancellation requested. Skip sending messages");
return;
}

utils::Async(
producer_task_processor_,
"producer_send_bulk",
Expand Down
7 changes: 3 additions & 4 deletions scripts/kafka/ubuntu_install_kafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# Exit on any error and treat unset variables as errors, print all commands
set -o errexit -o nounset -o pipefail -o posix -x

KAFKA_VERSION=4.0.1
KAFKA_VERSION=4.3.1
KAFKA_HOME=/etc/kafka
KAFKA_URL="https://www.apache.org/dyn/closer.lua/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz?action=download"

DEBIAN_FRONTEND=noninteractive sudo apt install -y openjdk-17-jdk

curl "https://dlcdn.apache.org/kafka/$KAFKA_VERSION/kafka_2.13-$KAFKA_VERSION.tgz" -o kafka.tgz
mkdir -p "$KAFKA_HOME"
tar -xzf kafka.tgz --directory="$KAFKA_HOME" --strip-components=1
rm kafka.tgz
curl -fsSL "$KAFKA_URL" | tar -xzf - --directory="$KAFKA_HOME" --strip-components=1
Loading