parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

LiveQuery Server is running, but not sending events

Open danawhite opened this issue 10 years ago • 23 comments

I am attempting to use LiveQuery subscriptions in a React Native project that I am currently building. The goal to facilitate communication and real-time updates between multiple devices. I have managed to configure my Parse and LiveQuery servers successfully. However, when I declare a subscription in my client code, I am not seeing the log statements in the console that were added for verification. I do, however, see that the subscription was created successfully. See below.

Server code:

 `const app = express(); `
 `app.use(
'/parse',
new ParseServer({
    databaseURI: DATABASE_URI,
    cloud: path.resolve(__dirname, 'cloud.js'),
    appId: APP_ID,
    masterKey: MASTER_KEY,
    fileKey: 'FILE_KEY',
    serverURL: "https://${SERVER_HOST}:${SERVER_PORT}/parse",
    liveQuery: {
        classNames: ['Class', 'AnotherClass'],
    }
})

);

 let httpServer = require('http').createServer(app);
 httpServer.listen(SERVER_PORT, () => {
console.log("parse server running on port ${SERVER_PORT}")
 });`

ParseServer.createLiveQueryServer(httpServer);

When I start the server, I see the following:
parse server running on port 1337 info: Parse LiveQuery Server starts running

On the client side...

                   `let query = new Parse.Query('Class');`
                    `query.equalTo("username", "[email protected]");
                    let subscription = query.subscribe();`

                    console.log(subscription); <-- this shows up in the console

                    subscription.on('open', () => {
                        console.log('subscription opened'); <-- this does not
                    });

                    subscription.on('create', (object) => {
                        console.log(`${object} created.`) <-- neither does this
                    })`

{

Expected Results

My expectation is that I would see the logs that would essentially verify that the subscription/socket is open so that I can write my logic accordingly.

Environment Setup

React Native 0.34.1

  • Server
    • parse-server version (Be specific! Don't say 'latest'.) : 2.2.22
    • Operating System: MacOS Sierra
    • Hardware: MacBook Pro
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [FILL THIS OUT]
  • Database
    • MongoDB version: 3.2.7
    • Localhost or remote server? I am running Parse Server on an AWS EC2 instance with mLab. However, I have been unsuccessful when using the EC2 url and localhost as the server url.
screen shot 2016-10-12 at 9 40 11 am

danawhite avatar Oct 12 '16 13:10 danawhite

Hmm, is "open" actually a valid event type? I just started using LiveQuery within the last couple weeks but I thought create, update, leave, enter and delete were the only types (https://github.com/ParsePlatform/parse-server/wiki/Parse-LiveQuery-Protocol-Specification).

chesterhawkins avatar Oct 12 '16 17:10 chesterhawkins

@chesterhawkins according to the Parse JavaScript guide, open is a valid event. Am I referencing old information? http://parseplatform.github.io/docs/js/guide/#live-queries

To that end, do you see anything in my configuration that differs from yours that would cause events to not emit in my code?

danawhite avatar Oct 12 '16 19:10 danawhite

Our configs are pretty much the same. Any luck yet? Might be a dumb question, but have you tried triggering the create event yet by creating a user with that username after starting up the server?

chesterhawkins avatar Oct 13 '16 17:10 chesterhawkins

@danawhite if the user is already created, you won't have any event.

flovilmart avatar Oct 13 '16 18:10 flovilmart

@chesterhawkins @flovilmart what versions of React, RN and Parse are you using to yield successful emitting of events other than an error event?

When I add the following:

Parse.LiveQuery.on('error', (error) => { console.log('Parse LiveQuery Error', error); });

I get a ton of errors in the debug console, but no other event types.

danawhite avatar Oct 13 '16 18:10 danawhite

Using iOS SDK and working on the Android one. Not checking ACL's as we're only working with publicly accessible objects

flovilmart avatar Oct 13 '16 21:10 flovilmart

Thanks. I was encountering too many roadblocks..decided to rip out Parse in favor of Firebase. It took maybe 4 hours to get up to speed and have things functioning properly.

danawhite avatar Oct 14 '16 14:10 danawhite

hey @danawhite, I know you already ripped out the Parse code but do you mind telling me where you placed the client code?

`let query = new Parse.Query('Class');`
                    `query.equalTo("username", "[email protected]");
                    let subscription = query.subscribe();`

                    console.log(subscription); <-- this shows up in the console

                    subscription.on('open', () => {
                        console.log('subscription opened'); <-- this does not
                    });

                    subscription.on('create', (object) => {
                        console.log(`${object} created.`) <-- neither does this
                    })`

willyyang avatar Nov 23 '16 15:11 willyyang

Currently going down a potential rabbit hole with the live query implementation

willyyang avatar Nov 23 '16 15:11 willyyang

Will,

I believe that code resided in the root of my app. I am using React Native so the file was index.ios.js.

Based on the fact that I was never able to get it working and that there does not seem to be much support for Live Query online these days, I would suggest that you count your losses and migrate to another backend solution. It literally took me 4 hours to replace Parse with Firebase and get the real-time database piece working on a basic level.

On Wed, Nov 23, 2016 at 10:34 AM, Will Yang [email protected] wrote:

Currently going down a potential rabbit hole with the live query implementation

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/2861#issuecomment-262548013, or mute the thread https://github.com/notifications/unsubscribe-auth/ABrADW1dWYgaTHvz0Sed_R98MpOlxoAkks5rBFz2gaJpZM4KUxIQ .

danawhite avatar Nov 23 '16 16:11 danawhite

Ok I'll play around with this some more and if it still doesn't work I'll look into FireBase. Thanks for your help.

On Wed, Nov 23, 2016 at 11:12 AM, Dana A. White [email protected] wrote:

Will,

I believe that code resided in the root of my app. I am using React Native so the file was index.ios.js.

Based on the fact that I was never able to get it working and that there does not seem to be much support for Live Query online these days, I would suggest that you count your losses and migrate to another backend solution. It literally took me 4 hours to replace Parse with Firebase and get the real-time database piece working on a basic level.

On Wed, Nov 23, 2016 at 10:34 AM, Will Yang [email protected] wrote:

Currently going down a potential rabbit hole with the live query implementation

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/ParsePlatform/parse-server/issues/2861#issuecomment- 262548013>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABrADW1dWYgaTHvz0Sed_ R98MpOlxoAkks5rBFz2gaJpZM4KUxIQ> .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/2861#issuecomment-262559010, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGZYbkrc2pYLZgAgKv7Rzf_NZSJ_hgxks5rBGXUgaJpZM4KUxIQ .

willyyang avatar Nov 23 '16 16:11 willyyang

@willyyang do you store your subscription somewhere in your JS code?

flovilmart avatar Nov 23 '16 16:11 flovilmart

@flovilmart

componentDidMount() {
    console.log('in componentDidMount')
    let query = new Parse.Query('Donations');
    query.equalTo('transporterId', '');
    this.subscription = query.subscribe();
    this.subscription.on('create', (donation) => {
      console.log('created donation')
      console.log(donation.get('transporterId')); // This should output `test`
    });
    this.subscription.on('update', (donation) => {
      console.log('THIS IS NOT WORKING')
      console.log(donation.get('transporterId')); // This should output `test`
    });
  }

Im putting it in componentDidMount ... The subscription to create works, but the subscription to updates does not.

willyyang avatar Nov 23 '16 16:11 willyyang

But your query only filters transporterId = '', so that makes sense that your subscription is not updated...

flovilmart avatar Nov 23 '16 16:11 flovilmart

yup I figured that out now. thanks.

On Wed, Nov 23, 2016 at 11:56 AM, Florent Vilmart [email protected] wrote:

But your query only filters transporterId = '', so that makes sense that your subscription is not updated...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ParsePlatform/parse-server/issues/2861#issuecomment-262571649, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGZYWmEBY1N2PIyb2m4afqucrIVXmcZks5rBHBXgaJpZM4KUxIQ .

willyyang avatar Nov 23 '16 16:11 willyyang

I was having this exact problem when trying to configure livequery using a server port like 80300 in a local installation ( I left parse server port at 1337 ). There were no errors or messages or nothing, it just didn't work. As soon as I defined a port like 8030 for live query it all started working and 'open' and 'create' events are now receiving events perfectly.

Note that in the client I also had to manually setup the livequery URL using: Parse.liveQueryServerURL = "ws://localhost:8030"

santiagoarriaga avatar Apr 03 '17 18:04 santiagoarriaga

hi @willyyang , could you tell me if query.containsAll is can use or not ? I try equalTo and containsAll not work

TVMD avatar Jan 24 '18 18:01 TVMD

guys , I m facing the same , only OPEN event works, others events doesn't work..

thunderwin avatar Sep 10 '19 13:09 thunderwin

@thunderwin Can you open a new issue and fill out the template?

dplewis avatar Sep 10 '19 16:09 dplewis

guys , I m facing the same , only OPEN event works, others events doesn't work..

This is probably because you did not add it to liveQuery: { classNames: [...] } in the server.

gazialankus avatar Nov 15 '20 19:11 gazialankus