RabbitMQ

  1. CREATE DATABASE IF NOT EXISTS event;
  2. USE event;
  3. CREATE TABLE IF NOT EXISTS event (
  4. `timestamp` DateTime,
  5. `id` UInt32,
  6. `body` String
  7. ) Engine = Memory;
  8. CREATE TABLE IF NOT EXISTS rabbitmq_entry
  9. (
  10. `timestamp` UInt64,
  11. `id` UInt32,
  12. `body` String
  13. ) ENGINE = RabbitMQ SETTINGS
  14. rabbitmq_host_port = 'rabbitmq:5672',
  15. rabbitmq_exchange_name = 'clickhouse-exchange',
  16. rabbitmq_routing_key_list = 'myqueue',
  17. rabbitmq_format = 'JSONEachRow',
  18. rabbitmq_exchange_type = 'fanout',
  19. rabbitmq_num_consumers = 1,
  20. rabbitmq_routing_key_list = 'myqueue'
  21. ;
  22. CREATE MATERIALIZED VIEW IF NOT EXISTS event_view
  23. TO event AS
  24. SELECT
  25. toDateTime(toUInt64(divide(timestamp, 1000000000))) AS timestamp,
  26. id AS id,
  27. body AS body
  28. FROM rabbitmq_entry;

Kafka

  1. CREATE TABLE queue (
  2. timestamp UInt64,
  3. level String,
  4. message String
  5. ) ENGINE = Kafka('localhost:9092', 'topic', 'group1', 'JSONEachRow');
  6. CREATE TABLE daily (
  7. day Date,
  8. level String,
  9. total UInt64
  10. ) ENGINE = SummingMergeTree(day, (day, level), 8192);
  11. CREATE MATERIALIZED VIEW consumer TO daily
  12. AS
  13. SELECT
  14. toDate(toDateTime(timestamp)) AS day,
  15. level, count() as total
  16. FROM
  17. queue GROUP BY day, level;