-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kafka: add upstream-kafka-consumer (#24431)
Signed-off-by: Adam Kotwasinski <adam.kotwasinski@gmail.com> Signed-off-by: Ryan Northey <ryan@synca.io>
- Loading branch information
1 parent
76fa8bd
commit fad1110
Showing
12 changed files
with
694 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
contrib/kafka/filters/network/source/mesh/inbound_record.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "absl/strings/str_cat.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace NetworkFilters { | ||
namespace Kafka { | ||
namespace Mesh { | ||
|
||
/** | ||
* Simple structure representing the record received from upstream Kafka cluster. | ||
*/ | ||
struct InboundRecord { | ||
|
||
const std::string topic_; | ||
const int32_t partition_; | ||
const int64_t offset_; | ||
|
||
// TODO (adam.kotwasinski) Get data in here in the next commits. | ||
|
||
InboundRecord(std::string topic, int32_t partition, int64_t offset) | ||
: topic_{topic}, partition_{partition}, offset_{offset} {}; | ||
|
||
// Used in logging. | ||
std::string toString() const { | ||
return absl::StrCat("[", topic_, "-", partition_, "/", offset_, "]"); | ||
} | ||
}; | ||
|
||
using InboundRecordSharedPtr = std::shared_ptr<InboundRecord>; | ||
|
||
} // namespace Mesh | ||
} // namespace Kafka | ||
} // namespace NetworkFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
contrib/kafka/filters/network/source/mesh/upstream_kafka_consumer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "envoy/common/pure.h" | ||
|
||
#include "contrib/kafka/filters/network/source/mesh/inbound_record.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace NetworkFilters { | ||
namespace Kafka { | ||
namespace Mesh { | ||
|
||
/** | ||
* An entity that is interested in inbound records delivered by Kafka consumer. | ||
*/ | ||
class InboundRecordProcessor { | ||
public: | ||
virtual ~InboundRecordProcessor() = default; | ||
|
||
/** | ||
* Passes the record to the processor. | ||
*/ | ||
virtual void receive(InboundRecordSharedPtr message) PURE; | ||
|
||
/** | ||
* Blocks until there is interest in records in a given topic, or timeout expires. | ||
* Conceptually a thick condition variable. | ||
* @return true if there was interest. | ||
*/ | ||
virtual bool waitUntilInterest(const std::string& topic, const int32_t timeout_ms) const PURE; | ||
}; | ||
|
||
using InboundRecordProcessorPtr = std::unique_ptr<InboundRecordProcessor>; | ||
|
||
/** | ||
* Kafka consumer pointing to some upstream Kafka cluster. | ||
*/ | ||
class KafkaConsumer { | ||
public: | ||
virtual ~KafkaConsumer() = default; | ||
}; | ||
|
||
using KafkaConsumerPtr = std::unique_ptr<KafkaConsumer>; | ||
|
||
} // namespace Mesh | ||
} // namespace Kafka | ||
} // namespace NetworkFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.