首页 > 解决方案 > Parse LiveQuery not receiving events AWS EB + Redis

问题描述

I am trying to set up parse LiveQuery but am getting stuck. On the client I am able to open the connection, but the LiveQuery won't update the client when I make a change on the server. What am I doing wrong? Is there a better way to set up?

Here is what I have going on in the client:

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)
});

My AWS Setup:

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

Here is my server config:

//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 + '.');
});

Here is my LiveQuery Server Settings:

//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
});

标签: amazon-web-servicesparse-platformredisparse-server

解决方案


检查您的 Nginx 配置。

这是专门为 AWS 制作的很棒的指南https://github.com/SoBump/ParseLiveQueryHelp/blob/master/guide.md 。

希望这可以帮助


推荐阅读