userver: userver/kafka/exceptions.hpp Source File
Loading...
Searching...
No Matches
exceptions.hpp
1#pragma once
2
3#include <stdexcept>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace kafka {
8
9/// @brief Base exception thrown by Producer::Send and Producer::SendAsync
10/// on send or delivery errors.
11class SendException : public std::runtime_error {
12 public:
13 using std::runtime_error::runtime_error;
14
15 /// @brief Returns whether it makes sense to retry failed send.
16 ///
17 /// @see
18 /// https://docs.confluent.io/platform/current/clients/librdkafka/html/md_INTRODUCTION.html#autotoc_md8
19 bool IsRetryable() const noexcept;
20
21 protected:
22 SendException(const char* what, bool is_retryable);
23
24 private:
25 const bool is_retryable_{false};
26};
27
28class DeliveryTimeoutException final : public SendException {
29 static constexpr const char* kWhat{
30 "Message is not delivered after `delivery_timeout` milliseconds. Hint: "
31 "Adjust `delivery_timeout` and `queue_buffering_*` options or manually "
32 "retry the send request."};
33
34 public:
35 DeliveryTimeoutException();
36};
37
38class QueueFullException final : public SendException {
39 static constexpr const char* kWhat{
40 "The sending queue is full - send request cannot be scheduled. Hint: "
41 "Manually retry the error or increase `queue_buffering_max_messages` "
42 "and/or `queue_buffering_max_kbytes` config option."};
43
44 public:
45 QueueFullException();
46};
47
48class MessageTooLargeException final : public SendException {
49 static constexpr const char* kWhat{
50 "Message size exceeds configured limit. Hint: increase "
51 "`message_max_bytes` config option."};
52
53 public:
54 MessageTooLargeException();
55};
56
57class UnknownTopicException final : public SendException {
58 static constexpr const char* kWhat{"Given topic does not exist in cluster."};
59
60 public:
61 UnknownTopicException();
62};
63
64class UnknownPartitionException final : public SendException {
65 static constexpr const char* kWhat = "Topic does not have given partition.";
66
67 public:
68 UnknownPartitionException();
69};
70
71} // namespace kafka
72
73USERVER_NAMESPACE_END