目前已经有了好几个presto nodejs 的client,为了方便presto-gateway 的连接,修改了一个现有的nodejs client
可以方便的连接presto-gateway

原理

因为通过通过的rest api 调用的,所以直接在原有上添加http header X-Presto-Routing-Group

  • 参考修改的presto client
 
https://github.com/tagomoris/presto-client-node
  • 修改的地方
    headers.js
// Add X-Presto-Routing-Group for support presto gateway
Headers.ROUTING_GROUP = 'X-Presto-Routing-Group';

index.js
对于查询支持添加routingGroup

Client.prototype.statementResource = function(opts) {
  var client = this;
  var columns = null;
  if (!opts.catalog && !this.catalog)
    throw {message: "catalog not specified"};
  if (!opts.schema && !this.schema)
    throw {message: "schema not specified"};
  if (!opts.success && !opts.callback)
    throw {message: "callback function 'success' (or 'callback') not specified"};
  var header = {};
  header[Headers.CATALOG] = opts.catalog || this.catalog;
  header[Headers.SCHEMA] = opts.schema || this.schema;
  if (opts.session)
    header[Headers.SESSION] = opts.session;
  if (opts.timezone)
    header[Headers.TIME_ZONE] = opts.timezone;
  if (opts.routingGroup)
    header[Headers.ROUTING_GROUP] = opts.routingGroup;
 
 
  • 说明
    已经push npm 仓库了

使用方法

  • 安装依赖
npm install @dalongrong/presto-client
  • 参考docker-compose 运行环境
version: "3"
services:
  proxy:
     image: dalongrong/presto-gateway:1.6.1
     ports:
     - "8888:8888"
     - "8082:8082"
     - "8083:8083"
     build: ./
     volumes:
     - "./config.yml.template:/config.yml.template"
  presto1:
     image: starburstdata/presto
     ports:
     - "8080:8080"
  presto2:
     image: starburstdata/presto
     ports:
     - "8081:8080"
  • 配置文件
requestRouter:
  port: 8888
  name: prestoRouter
  cacheDir: /var/log/prestoproxy/cache
  historySize: 1000
backends:
  - localPort: 8082
    name: presto1
    proxyTo: http://presto1:8080
    routingGroup: adhoc
  - localPort: 8083
    name: presto2
    proxyTo: http://presto2:8080
    routingGroup: scheduled
server:
  applicationConnectors:
    - type: http
      port: 8090
  adminConnectors:
    - type: http
      port: 8091
notifier:
  smtpHost: localhost
  smtpPort: 587
  sender: presto-gw-monitor-noreply@lyft.com
  recipients:
    - prestodev@yourorg.com
modules:
  - com.lyft.data.gateway.module.ProxyBackendProviderModule
  - com.lyft.data.gateway.module.GatewayProviderModule
  - com.lyft.data.gateway.module.NotifierModule
managedApps:
  - com.lyft.data.gateway.GatewayManagedApp
  - com.lyft.data.gateway.ActiveClusterMonitor
# Logging settings.
logging:
  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO
  # Logger-specific levels.
  loggers:
    com.lyft: DEBUG
  appenders:
    - type: console
    - type: file
      currentLogFilename: /var/log/prestoproxy/prestoproxy-java.log
      archivedLogFilenamePattern: /var/log/prestoproxy/prestoproxy-java-%d{yyyy-MM-dd}-%i.log.gz
      archivedFileCount: 7
      timeZone: UTC
      maxFileSize: 100MB
 
 
  • 参考代码
var presto = require('@dalongrong/presto-client');
var client = new presto.Client({
  user: 'appdemo',
  host: "localhost",
  port: 8888
});
client.execute({
  query: 'select * from nation2',
  catalog: 'memory',
  schema: 'default',
  source: 'nodejs-client',
  routingGroup: 'scheduled',
  state: function (error, query_id, stats) {
    console.log(error)
    console.log({
      message: "status changed",
      id: query_id,
      stats: stats
    });
  },
  columns: function (error, data) {
    console.log({
      resultColumns: data
    });
  },
  data: function (error, data, columns, stats) {
    console.log(data);
  },
  success: function (error, stats) {
    console.log(stats)
  },
  error: function (error) {
    console.log(error)
  }
});

参考资料

https://github.com/tagomoris/presto-client-node
https://github.com/rongfengliang/presto-client-node

presto-gateway nodejs client的更多相关文章

  1. C# Socket TCP Server & Client & nodejs client

    要调试公司某项目里的一个功能,因为要准备测试环境,趁这个机会重温了一下Socket(全还给老师了 -_-#),做个备份. C# Server static void Main(string[] arg ...

  2. What's New In Zeebe: Scaling Zeebe, New Client APIs, Faster Requests, Timestamps, NodeJS Client, and Default Topic is Back!

    Written by Daniel Meyer on May 16 2018 in the What's New In Zeebe category. Welcome to the first-eve ...

  3. NodeJS client code websocket

    var WebSocketClient = require('websocket').client; var client = new WebSocketClient(); client.on('co ...

  4. Nodejs Client for FastDFS

    FastDFS 是分布式文件存储系统.这个项目是FastDFS的NodeJS客户端,用来与FastDFS Server进行交互,进行文件的相关操作.我测试过的server版本是4.0.6. githu ...

  5. Nodejs学习笔记(九)--- 与Redis的交互(mranney/node_redis)入门

    目录 简介和安装 redis简介 redis安装 redis运行 node_redis安装 连接到redis服务器redis.createClient() 认证 client.auth(passwor ...

  6. Gearman + Nodejs + MySQL UDF异步实现 MySQL 到 Redis 的数据同步

    [TOC] 1, 环境 CentOS, MySQL, Redis, Nodejs 2, Redis简介 Redis是一个开源的K-V内存数据库,它的key可以是string/set/hash/list ...

  7. gRPC中Any类型的使用(Java和NodeJs端)

    工作中要把原来Java服务端基于SpringMVC的服务改为使用gRPC直接调用.由于原Service的返回值为动态的Map类型,key值不确定,且value的类型不唯一,因此使用了protobuf ...

  8. 【原创】大叔问题定位分享(33)beeline连接presto报错

    hive2.3.4 presto0.215 使用hive2.3.4的beeline连接presto报错 $ beeline -d com.facebook.presto.jdbc.PrestoDriv ...

  9. 数仓1.4 |业务数仓搭建| 拉链表| Presto

    电商业务及数据结构 SKU库存量,剩余多少SPU商品聚集的最小单位,,,这类商品的抽象,提取公共的内容 订单表:周期性状态变化(order_info) id 订单编号 total_amount 订单金 ...

随机推荐

  1. nginx location指令详解

    Nginx的HTTP配置主要包括三个区块,结构如下: http { //这个是协议级别 include mime.types; default_type application/octet-strea ...

  2. drools -规则语法

    文章结构 1. 基础api 2. FACT对象 3. 规则 4. 函数 1. 基础api 在 Drools 当中,规则的编译与运行要通过Drools 提供的各种API 来实现,这些API 总体来讲可以 ...

  3. 基于C#实现的单点登录

    了解或想探索单点登录的朋友应该对单点登录有一个大致的了解,在这里我不在过多的阐述单点登录的概念. 单点登录说的通俗一点,就是一处登录(统一认证中心--Server),处处通行(Client). 一.第 ...

  4. Winform串口编程---接收数据demo(VSPD虚拟串口)

    参考地址:https://blog.csdn.net/memgxingfeixiang/article/details/52513970  https://blog.csdn.net/kevin_io ...

  5. Angular复习笔记7-路由(下)

    Angular复习笔记7-路由(下) 这是angular路由的第二篇,也是最后一篇.继续上一章的内容 路由跳转 Web应用中的页面跳转,指的是应用响应某个事件,从一个页面跳转到另一个页面的行为.对于使 ...

  6. MongoDB netcore

    mongodb.driver mongodb.driver.core url:  http://dl.mongodb.org/dl/win32/x86_64 ********************* ...

  7. python爬虫---爬虫的数据解析的流程和解析数据的几种方式

    python爬虫---爬虫的数据解析的流程和解析数据的几种方式 一丶爬虫数据解析 概念:将一整张页面中的局部数据进行提取/解析 作用:用来实现聚焦爬虫的吧 实现方式: 正则 (针对字符串) bs4 x ...

  8. Calendar类set方法中的坑

    最近写了一个支付宝微信对账报表,发现系统金额比支付宝微信的少好多,左查右查发现是追缴金额没统计到,再一查发现月结束日期为2019-09-31,9月咋会有31,为啥呢就追缴金额不行呢,因为其他类型用TI ...

  9. windows 2003 域控服务器导出全部hash的方法

    天下文章一大抄,我也是醉了... 一份“错误”的文章一遍又一遍的被转载,盲目转载,根本不细看.只会误导新手. 谈下windows2003域控下如何导出全部的hash信息. 1. 使用备份还原向导 2. ...

  10. day 38

    目录 元类 什么是元类 元类的作用 怎么自定义创建元类 元类 什么是元类 用class关键字定义的类本身是一个对象,负责产生该对象的类称之为元类(元类可以简称为类的类),内置的元类为type 元类的作 ...