码迷,mamicode.com
首页 > Web开发 > 详细

presto-gateway nodejs client

时间:2019-08-24 11:45:40      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:containe   ade   setting   reply   serve   api   mes   llb   std   

目前已经有了好几个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

标签:containe   ade   setting   reply   serve   api   mes   llb   std   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!