1

我正在设置一个快速网关实例,用于将请求路由到微服务。它按预期工作,但是当我尝试在我的系统配置中包含 redis 时出现以下错误

0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:policy] error: Failed to initialize custom express-session store, please ensure you have connect-redis npm package installed
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:gateway] error: Could not hot-reload gateway.config.yml. Configuration is invalid. Error: A client must be directly provided to the RedisStore
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:gateway] warn: body-parser policy hasn't provided a schema. Validation for this policy will be skipped.
0|apigateway-service  | 2020-01-09T18:50:10.118Z [EG:policy] error: Failed to initialize custom express-session store, please ensure you have connect-redis npm package installed

我已经安装了必要的软件包

npm install redis connect-redis express-session

并像这样更新了 system.config.yml 文件,

# Core
db:
  redis:
    host: ${REDIS_HOST}
    port: ${REDIS_PORT}
    db: ${REDIS_DB}
    namespace: EG

plugins:
  # express-gateway-plugin-example:
  #   param1: 'param from system.config'
  health-check:
    package: './health-check/manifest.js'
  body-parser:
    package: './body-parser/manifest.js'

crypto:
  cipherKey: sensitiveKey
  algorithm: aes256
  saltRounds: 10

# OAuth2 Settings
session:
  storeProvider: connect-redis
  storeOptions:
    host: ${REDIS_HOST}
    port: ${REDIS_PORT}
    db: ${REDIS_DB}
  secret: keyboard cat # replace with secure key that will be used to sign session cookie
  resave: false
  saveUninitialized: false
accessTokens:
  timeToExpiry: 7200000
refreshTokens:
  timeToExpiry: 7200000
authorizationCodes:
  timeToExpiry: 300000

我的 gateway.config.yml 文件看起来像这样

http:
  port: 8080
admin:
  port: 9876
apiEndpoints:
  accounts:
    paths: '/accounts*'
  billing:
    paths: '/billing*'

serviceEndpoints:
  accounts:
    url: ${ACCOUNTS_URL}
  billing:
    url: ${BILLING_URL}

policies:
  - body-parser
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit

pipelines:
  accounts:
    apiEndpoints:
      - accounts
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
    # - key-auth:
      - body-parser:
      - log: # policy name
        - action:    # array of condition/actions objects
        message: ${req.method} ${req.originalUrl} ${JSON.stringify(req.body)} # parameter for log action
      - proxy:
        - action:
            serviceEndpoint: accounts
            changeOrigin: true
            prependPath: true
            ignorePath: false
            stripPath: true
  billing:
    apiEndpoints:
      - billing
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
    # - key-auth:
      - body-parser:
      - log: # policy name
        - action:    # array of condition/actions objects
        message: ${req.method} ${req.originalUrl} ${JSON.stringify(req.body)} # parameter for log action
      - proxy:
        - action:
            serviceEndpoint: billing
            changeOrigin: true
            prependPath: true
            ignorePath: false
            stripPath: true

包.json

{
  "name": "max-apigateway-service",
  "description": "Express Gateway Instance Bootstraped from Command Line",
  "repository": {},
  "license": "UNLICENSED",
  "version": "1.0.0",
  "main": "server.js",
  "dependencies": {
    "connect-redis": "^4.0.3",
    "express-gateway": "^1.16.9",
    "express-gateway-plugin-example": "^1.0.1",
    "express-session": "^1.17.0",
    "redis": "^2.8.0"
  }
}

我错过了什么吗?

4

1 回答 1

0

在我的例子中,我将 AWS Elasticache 用于 Redis。我尝试运行它,但出现“必须直接向 RedisStore 提供客户端”错误。我从安全组设置中发现了我的问题。EC2(server) 应该有一个适当的 Elasticache 端口的安全组。和 Elasticache 应该有相同的安全组。

步骤1。创建新的安全组。设置入站规则

在此处输入图像描述

第2步。将安全组添加到 EC2 服务器。 在此处输入图像描述

第三步。将安全组添加到 Elasticache。 在此处输入图像描述

于 2020-06-30T06:22:20.663 回答