2020-05-20 09:40:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
#include <Processors/ISource.h>
|
2020-05-20 09:40:49 +00:00
|
|
|
#include <Storages/RabbitMQ/StorageRabbitMQ.h>
|
|
|
|
#include <Storages/RabbitMQ/ReadBufferFromRabbitMQConsumer.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-07-13 01:11:35 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
class RabbitMQSource : public ISource
|
2020-05-20 09:40:49 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2021-10-07 08:26:08 +00:00
|
|
|
RabbitMQSource(
|
2020-05-20 09:40:49 +00:00
|
|
|
StorageRabbitMQ & storage_,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_,
|
2020-08-28 08:52:02 +00:00
|
|
|
const Names & columns,
|
2020-08-31 16:34:16 +00:00
|
|
|
size_t max_block_size_,
|
2021-11-03 12:43:23 +00:00
|
|
|
bool ack_in_suffix = false);
|
2020-05-20 09:40:49 +00:00
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
~RabbitMQSource() override;
|
2020-05-20 09:40:49 +00:00
|
|
|
|
|
|
|
String getName() const override { return storage.getName(); }
|
2020-12-05 21:55:00 +00:00
|
|
|
ConsumerBufferPtr getBuffer() { return buffer; }
|
2020-05-20 09:40:49 +00:00
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
Chunk generate() override;
|
2020-05-20 09:40:49 +00:00
|
|
|
|
2020-10-25 07:44:04 +00:00
|
|
|
bool queueEmpty() const { return !buffer || buffer->queueEmpty(); }
|
2020-08-31 16:34:16 +00:00
|
|
|
bool needChannelUpdate();
|
2020-08-28 08:52:02 +00:00
|
|
|
void updateChannel();
|
|
|
|
bool sendAck();
|
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
|
|
|
|
void setTimeLimit(Poco::Timespan max_execution_time_) { max_execution_time = max_execution_time_; }
|
|
|
|
|
2020-05-20 09:40:49 +00:00
|
|
|
private:
|
|
|
|
StorageRabbitMQ & storage;
|
2021-07-09 03:15:41 +00:00
|
|
|
StorageSnapshotPtr storage_snapshot;
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context;
|
2020-05-20 09:40:49 +00:00
|
|
|
Names column_names;
|
2020-08-31 16:34:16 +00:00
|
|
|
const size_t max_block_size;
|
2020-08-28 08:52:02 +00:00
|
|
|
bool ack_in_suffix;
|
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
bool is_finished = false;
|
2020-07-13 01:11:35 +00:00
|
|
|
const Block non_virtual_header;
|
|
|
|
const Block virtual_header;
|
2020-05-20 09:40:49 +00:00
|
|
|
|
|
|
|
ConsumerBufferPtr buffer;
|
2021-10-07 08:26:08 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
Poco::Timespan max_execution_time = 0;
|
|
|
|
Stopwatch total_stopwatch {CLOCK_MONOTONIC_COARSE};
|
|
|
|
|
|
|
|
bool checkTimeLimit() const;
|
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
RabbitMQSource(
|
|
|
|
StorageRabbitMQ & storage_,
|
2021-11-09 12:36:25 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot_,
|
2021-10-07 08:26:08 +00:00
|
|
|
std::pair<Block, Block> headers,
|
|
|
|
ContextPtr context_,
|
|
|
|
const Names & columns,
|
|
|
|
size_t max_block_size_,
|
|
|
|
bool ack_in_suffix);
|
|
|
|
|
|
|
|
Chunk generateImpl();
|
2020-05-20 09:40:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|