目前已经有了好几个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. SET QUOTED_IDENTIFIER选项对索引的影响

    早上来到公司,发现用于整理索引碎片的Job跑失败了,查看job history,发现以下错误消息: ALTER INDEX failed because the following SET optio ...

  2. Tomcat 路由请求的实现 Mapper

    在分析 Tomcat 实现之前,首先看一下 Servlet 规范是如何规定容器怎么把请求映射到一个 servlet.本文首发于(微信公众号:顿悟源码) 1. 使用 URL 路径 收到客户端请求后,容器 ...

  3. WPF设置全局控件样式

    原文:WPF设置全局控件样式 方法: 在资源文件APP.XAML中添加如下资源 <Application x:Class="_360UI.App" xmlns="h ...

  4. Oracle 加解密教程

    参考Oracle官方文档 在Oracle使用dbms_crypto包进行加解密 首先,授权当前用户使用加解密包 在sql中运行:connect sqlplus as sysdbagrant execu ...

  5. Mysql数据库中条件查询

    1.concat(字符串拼接) 作用:将选中的列进行拼接  写法 AS的作用就是属性名 SELECT CONCAT(ename,job) AS 你猜 FROM emp; 2.条件查询 语法: sele ...

  6. webpack 里的 import, exports 实现原理

    在使用 webpack 对脚本进行打包, 在开发中, 每个文件中都会使用 import 语句来导入一些功能,又会使用 export 语句导出一些功能,为了研究 import 和 export 原理,研 ...

  7. Delphi - ShellExecute资料

    Windows官方资料: https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea#p ...

  8. Spring Boot加载application.properties配置文件顺序规则

    SpringApplication会从以下路径加载所有的application.properties文件: 1.file:./config/(当前目录下的config文件夹) 2.file:./(当前 ...

  9. App的开发过程(转载)

    来源:https://www.cnblogs.com/sanwenyu/p/7234616.html 不同的项目管理模式或许会有完全不同的流程步骤.但是专业性几乎是保证产品质量的唯一准则. App的开 ...

  10. mybatis + oracle,出现ORA-01461:仅能绑定要插入LONG列的LONG值

    1.这个异常是指,用户向数据库执行插入数据操作时,某条数据的某个字段值过长,如果是varchar2类型的,当长度超过2000,--4000(最大值)之间的时候,oracle会自动将该字段值转为long ...