cubestore 运行试用

官方提供了docker-compose 的运行模式

环境准备

  • docker-compose 文件
version: "3"
services:
  cubestore_router:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_LOG_LEVEL=trace
      - CUBESTORE_SERVER_NAME=cubestore_router:9999
      - CUBESTORE_META_PORT=9999
      - CUBESTORE_WORKERS=cubestore_worker_1:9001,cubestore_worker_2:9001
      - CUBESTORE_REMOTE_DIR=/cube/data
    ports: 
    - "9999:9999"
    - "3030:3030"
    - "3306:3306"
    expose:
      - 9999 # This exposes the Metastore endpoint
      - 3030 # This exposes the HTTP endpoint for CubeJS
      - 3306
    volumes:
      - .cubestore:/cube/data
  cubestore_worker_1:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_SERVER_NAME=cubestore_worker_1:9001
      - CUBESTORE_WORKER_PORT=9001
      - CUBESTORE_META_ADDR=cubestore_router:9999
      - CUBESTORE_REMOTE_DIR=/cube/data
    depends_on:
      - cubestore_router
    expose:
      - 9001
    volumes:
      - .cubestore:/cube/data
  cubestore_worker_2:
    restart: always
    image: cubejs/cubestore:latest
    environment:
      - CUBESTORE_SERVER_NAME=cubestore_worker_2:9001
      - CUBESTORE_WORKER_PORT=9001
      - CUBESTORE_META_ADDR=cubestore_router:9999
      - CUBESTORE_REMOTE_DIR=/cube/data
    depends_on:
      - cubestore_router
    expose:
      - 9001
    volumes:
      - .cubestore:/cube/data

cube app 集成

主要是环境变量的配置

  • env
CUBEJS_DB_HOST=<host>
CUBEJS_DB_PORT=<port>
CUBEJS_DB_NAME=<db>
CUBEJS_DB_USER=<user>
CUBEJS_DB_PASS=<pass>
CUBEJS_WEB_SOCKETS=true
CUBEJS_DEV_MODE=true
CUBEJS_EXT_DB_HOST=localhost
CUBEJS_EXT_DB_PORT=3030
CUBEJS_EXT_DB_NAME=demoapp
CUBEJS_EXT_DB_TYPE=cubestore
CUBEJS_DB_TYPE=postgres
CUBEJS_API_SECRET=f2e81fe4b53200faac37bfe66d0be5b8a859e69c77c8f55134c5dd3afad5bab72fef5e346766ba485619ea0a5d8e577df5b4964a4b6b716162a72f590dd8c181
  • 效果

代码集成

使用mysql 连接cubestore

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  database : 'demoapp'
});
 
connection.connect();
 //  此处table 需要调整
connection.query('select * from dev_pre_aggregations.oc_order_main_tyccmc1j_dfnarpsv_1g8ppb2', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results);
});
 
connection.end();

说明

经过测试效果还是很明显的

参考资料

https://cube.dev/docs/pre-aggregations
https://cube.dev/docs/caching/using-pre-aggregations#running-in-production
https://cube.dev/blog/introducing-cubestore/
https://github.com/rongfengliang/cubestore-learning

原文地址:https://www.cnblogs.com/rongfengliang/p/14724133.html