parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.9k stars 4.78k forks source link

Parse LiveQuery not updating client #5610

Closed kurry421 closed 5 years ago

kurry421 commented 5 years ago

Issue Description

I have setup Livequery however when I update the database, the client is not receiving the update notification.

Steps to reproduce

On the client I subscribe to the Livequery server. I send a message (write a new object to db). However Livequery does not send any update on the client.

Expected Results

Client Side Code:

//Live Query Setup
Parse.liveQueryServerURL = 'ws://my-parse-live-query-server.us-east-1.elasticbeanstalk.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 fires correctly
    });
    subscription.on('create', function (message) {
        console.log("create: ", message); //This does not fire when new object created in db.
    });
    subscription.on('update', function (message) {
        console.log("update: ", message); //This doesn't fire when the DB is updated.
    });
})
.catch(error => {
    console.log(error)
});

Actual Outcome

There is no Livequery notification on update/create.

Environment Setup

-Client JS

Server Main App Setup Code:

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

Server Live Query App Setup Code

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

On AWS, I set up the NGINX for both env and set up Security group for the Elasticache:

Elasticache Security group for inbound

Type | Protocol | Port Range | Source | Description
All traffic | All | All | sg-dd6850a8 (default) |  
Custom TCP Rule | TCP | 80 - 8080 | 0.0.0.0/0 |  
Custom TCP Rule | TCP | 80 - 8080 | ::/0 |  

Logs/Trace

> parse-server-example@1.4.0 start /var/app/current
> node index.js

parse-server-example running on port 8081.
info: Create new client: 319d5d4f-b1f2-474d-9c81-742f67633e40
info: Client disconnect: 319d5d4f-b1f2-474d-9c81-742f67633e40
info: Create new client: fa93bb31-77f5-4f8a-af95-11f3d5841f5a
dplewis commented 5 years ago

Can you run the server VERBOSE=1?

kurry421 commented 5 years ago

Hey @dplewis thanks for your reply. In my server set up I included logLevel: "VERBOSE" but the logs are not showing anything more verbose.. is my set up incorrect?

var api = new ParseServer({
  appName: AppName,
  databaseURI: databaseUri,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  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",
  logLevel: "VERBOSE",
  verbose: true
});
ParseServer.createLiveQueryServer(httpServer, {
  appId: process.env.APP_ID, 
  masterKey: process.env.MASTER_KEY,
  serverURL: process.env.SERVER_URL,
  javascriptKey: process.env.JAVASCRIPT_KEY,
  redisURL: process.env.redisURL,
  websocketTimeout: 10 * 1000,
  cacheTimeout: 60 * 600 * 1000,
  logLevel: "VERBOSE",
  verbose: true
});
dplewis commented 5 years ago

I don’t see where you are saving objects in your log. Are they "Room" objects?

kurry421 commented 5 years ago

im scratching my head as to why the logs aren't printing it out.

But, the Room class has a relation to Messages class.

When a client saves a message, it saves it in the Messages class and attaches the new object as a relation to the Room class.

dplewis commented 5 years ago

Live Query doesn’t handle relations. You could do an array of ObjectIds as a work around

kurry421 commented 5 years ago

Thanks for the suggestion - question -since client is subscribed to Messages class on Livequery, shouldn't the client get an update when a new object is created/saved? edit - I guess it depends on the query client side, I updated so that client subscribed on Messages class. No dice when I update/add new message.

I just tested your suggestion on the Room class - I added a new column in the Room class, and manually added an array of strings while client connection was enabled. The client was not receiving the updates or create events

kurry421 commented 5 years ago

update digging deeper into this, it looks like functionality is working as expected locally. this leads me to believe that may be an AWS EB and/or Redis connection issue that is preventing when running correctly from the cloud.

dplewis commented 5 years ago

Check your Nginx Configuration.

Here is a great guide that was made specifically for AWS

AnthonySoler commented 3 years ago

Live Query doesn’t handle relations. You could do an array of ObjectIds as a work around

Hello,

Thank you for this information.

Is there an article in the documentation where such limitations regarding LiveQueries are listed? I was not able to find this information in the following documentations (maybe I missed something):

It would be great to have them listed with a few workarounds for these known limitations.

Have a good day,

MaidaShahid commented 1 year ago

Hi everyone.. I'm facing the same issue.. My open event is triggered.. but my create and update events are not working.. i'm writing my client in angular.. Kindly inform how did you resolve your issue..??