【发布时间】:2019-05-22 20:30:06
【问题描述】:
我正在尝试设置解析 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
});
【问题讨论】:
-
您能否详细说明如何更改服务器端的数据?是通过 API,Parse Dashboard 吗?.. 如果您为 Room 类创建新记录,根据您的代码,您应该在客户端收到事件。
-
你能确认两个应用程序上的 process.env.redisURL 相同吗?
标签: amazon-web-services parse-platform redis parse-server