Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
chunk_integrations.hpp
Go to the documentation of this file.
1/**
2 * @file chunk_integrations.hpp
3 * @brief Integration utilities for external systems and databases
4 * @author Jonathan Reich
5 * @date 2024-12-07
6 */
7
8#pragma once
9#include "chunk_common.hpp"
10#include <memory>
11#include <string>
12#include <vector>
13
15
16/**
17 * @brief Abstract base class for database connections
18 */
20public:
21 virtual ~DatabaseConnection() = default;
22
23 /**
24 * @brief Connect to database
25 * @param connection_string Database connection parameters
26 * @throws std::runtime_error if connection fails
27 */
28 virtual void connect(const std::string& connection_string) = 0;
29
30 /**
31 * @brief Disconnect from database
32 */
33 virtual void disconnect() = 0;
34};
35
36/**
37 * @brief Class for storing chunks in various databases
38 */
40public:
41 /**
42 * @brief Constructor
43 * @param connection Database connection instance
44 * @param table_name Target table name
45 */
46 DatabaseChunkStore(std::unique_ptr<DatabaseConnection> connection,
47 const std::string& table_name);
48
49 /**
50 * @brief Store chunks in PostgreSQL database
51 * @tparam T Data type of chunk elements
52 * @param chunks Vector of chunks to store
53 * @throws std::runtime_error if storage fails
54 */
55 template <typename T>
56 void store_chunks_postgres(const std::vector<std::vector<T>>& chunks);
57
58 /**
59 * @brief Store chunks in MongoDB database
60 * @tparam T Data type of chunk elements
61 * @param chunks Vector of chunks to store
62 * @throws std::runtime_error if storage fails
63 */
64 template <typename T>
65 void store_chunks_mongodb(const std::vector<std::vector<T>>& chunks);
66
67private:
68 std::unique_ptr<DatabaseConnection> db_connection; ///< Database connection
69 std::string table; ///< Target table name
70};
71
72/**
73 * @brief Abstract base class for message queue connections
74 */
76public:
77 virtual ~MessageQueueConnection() = default;
78
79 /**
80 * @brief Connect to message queue
81 * @param connection_string Connection parameters
82 */
83 virtual void connect(const std::string& connection_string) = 0;
84
85 /**
86 * @brief Disconnect from message queue
87 */
88 virtual void disconnect() = 0;
89};
90
91/**
92 * @brief Class for publishing chunks to message queues
93 */
95public:
96 /**
97 * @brief Constructor
98 * @param connection Message queue connection instance
99 * @param queue_name Target queue name
100 */
101 ChunkMessageQueue(std::unique_ptr<MessageQueueConnection> connection,
102 const std::string& queue_name);
103
104 /**
105 * @brief Publish chunks to Kafka topic
106 * @tparam T Data type of chunk elements
107 * @param chunks Vector of chunks to publish
108 * @throws std::runtime_error if publishing fails
109 */
110 template <typename T>
111 void publish_chunks_kafka(const std::vector<std::vector<T>>& chunks);
112
113 /**
114 * @brief Publish chunks to RabbitMQ queue
115 * @tparam T Data type of chunk elements
116 * @param chunks Vector of chunks to publish
117 * @throws std::runtime_error if publishing fails
118 */
119 template <typename T>
120 void publish_chunks_rabbitmq(const std::vector<std::vector<T>>& chunks);
121
122private:
123 std::unique_ptr<MessageQueueConnection> mq_connection; ///< Message queue connection
124 std::string queue; ///< Target queue name
125};
126
127} // namespace chunk_integrations
#define CHUNK_EXPORT
Class for publishing chunks to message queues.
void publish_chunks_kafka(const std::vector< std::vector< T > > &chunks)
Publish chunks to Kafka topic.
ChunkMessageQueue(std::unique_ptr< MessageQueueConnection > connection, const std::string &queue_name)
Constructor.
std::unique_ptr< MessageQueueConnection > mq_connection
Message queue connection.
void publish_chunks_rabbitmq(const std::vector< std::vector< T > > &chunks)
Publish chunks to RabbitMQ queue.
Class for storing chunks in various databases.
DatabaseChunkStore(std::unique_ptr< DatabaseConnection > connection, const std::string &table_name)
Constructor.
void store_chunks_mongodb(const std::vector< std::vector< T > > &chunks)
Store chunks in MongoDB database.
std::unique_ptr< DatabaseConnection > db_connection
Database connection.
void store_chunks_postgres(const std::vector< std::vector< T > > &chunks)
Store chunks in PostgreSQL database.
Abstract base class for database connections.
virtual void connect(const std::string &connection_string)=0
Connect to database.
virtual void disconnect()=0
Disconnect from database.
Abstract base class for message queue connections.
virtual void disconnect()=0
Disconnect from message queue.
virtual void connect(const std::string &connection_string)=0
Connect to message queue.