解析 LiveQuery 不接收事件 AWS EB + Redis

Parse LiveQuery not receiving events AWS EB + Redis

我正在尝试设置解析 LiveQuery 但卡住了。在客户端上,我可以打开连接,但是当我在服务器上进行更改时,LiveQuery 不会更新客户端。我究竟做错了什么?有没有更好的设置方法?

这是我在客户端中进行的操作:

Parse.liveQueryServerURL = 'ws://myawsEB-LiveQuery.com'


var Message = Parse.Object.extend('Room');
var query = new Parse.Query(Message);
    query.include("messages");

// Subscribes to incoming messages
query.subscribe().then(subscription =>{

    subscription.on('open', () => {
     console.log('subscription opened'); // THIS WORKS!
    });

    subscription.on('create', function (message) {
        console.log("create: ", message); //THIS DOES NOT WORK
    });

    subscription.on('update', function (message) {
        console.log("update: ", message); //THIS DOES NOT WORK
    });
})
.catch(error => {
    console.log(error)
});

我的 AWS 设置:

AWS EB - Main App
AWS EB - Parse LiveQuery
AWS ElastiCache - Redis

这是我的服务器配置:

//Main APP
var api = new ParseServer({
  appName: "app-name",
  databaseURI: databaseUri,
  cloud: process.env.CLOUD_CODE_MAIN,
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY
  fileKey: process.env.FILE_KEY,
  serverURL: process.env.SERVER_URL,
  publicServerURL: process.env.SERVER_URL,
  clientKey: process.env.CLIENT_KEY,
  javascriptKey: process.env.JAVASCRIPT_KEY,
  liveQuery: {
    classNames: ["Room", "Messages"], // List of classes to support for query subscriptions
    redisURL: process.env.redisURL
  },
  databaseOptions: { poolSize: 500 },
  maxUploadSize: "5mb",
  verbose: true
});
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

这是我的 LiveQuery 服务器设置:

//Live Query Server

var express = require('express');
var cors = require('cors')
var ParseServer = require('parse-server').ParseServer;

var app = express();
app.use(cors());

// We include the lines below so that we can hit `/` and it passes the Elastic Beanstalk Health Check
app.get('/', function(req, res) {
  res.status(200).send('Make sure to star the parse-server repo on GitHub!');
});

var port = process.env.PORT || 1338;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

ParseServer.createLiveQueryServer(httpServer, {
  appId: process.env.APP_ID, // same as main-index.js file below
  masterKey: process.env.MASTER_KEY, // same as main-index.js 
  serverURL: process.env.SERVER_URL, // socket.myApp.com
  javascriptKey: process.env.JAVASCRIPT_KEY,
  redisURL: process.env.redisURL,
  websocketTimeout: 10 * 1000,
  cacheTimeout: 60 * 600 * 1000,
  verbose: true
});

检查您的 Nginx 配置。

这是一个很棒的指南https://github.com/SoBump/ParseLiveQueryHelp/blob/master/guide.md 专为 AWS 设计。

希望对您有所帮助