我正在尝试设置parse 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设计的。
希望这有帮助

关于amazon-web-services - 解析LiveQuery不接收事件AWS EB + Redis,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56264568/

10-08 21:53