parse-community / parse-server

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

LiveQuery Server is running, but not sending events #2861

Closed danawhite closed 8 years ago

danawhite commented 8 years ago

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", "dana@gmail.com");
                    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

screen shot 2016-10-12 at 9 40 11 am
chesterhawkins commented 8 years ago

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).

danawhite commented 8 years ago

@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?

chesterhawkins commented 8 years ago

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?

flovilmart commented 8 years ago

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

danawhite commented 8 years ago

@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.

flovilmart commented 8 years ago

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

danawhite commented 8 years ago

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.

willyyang commented 8 years ago

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", "dana@gmail.com");
                    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 commented 8 years ago

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

danawhite commented 8 years ago

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 notifications@github.com 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 .

willyyang commented 8 years ago

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 notifications@github.com 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 notifications@github.com 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 .

flovilmart commented 8 years ago

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

willyyang commented 8 years ago

@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.

flovilmart commented 8 years ago

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

willyyang commented 8 years ago

yup I figured that out now. thanks.

On Wed, Nov 23, 2016 at 11:56 AM, Florent Vilmart notifications@github.com 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 .

santiagoarriaga commented 7 years ago

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"

TVMD commented 6 years ago

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

thunderwin commented 5 years ago

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

dplewis commented 5 years ago

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

gazialankus commented 4 years ago

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.

c0sm1cdus7 commented 3 years ago

Hey everyone, I'm facing the same issue, the clients receives the "open" event but no "create" or "update" events.

Server configuration running Parse Server ^4.5.0:

var app = express();
app.use(compression());
app.enable('trust proxy');
app.use(bodyParser.json({limit: '50mb'}));
app.use(compression());
app.use(cookieParser());
app.use(device.capture());

app.use('/parse', new ParseServer({
    databaseURI: DATABASE_URI,
    appId: APP_ID,
    masterKey: MASTER_KEY,
    serverURL: 'http://localhost/parse',
    cloud: __dirname + '/cloud/main.js',
    liveQuery: {
        classNames: ['Order', 'Sale']
    }
}));

app.set('view engine', 'ejs');
app.use('/', routes);

const httpServer = require('http').createServer(app);
httpServer.listen(80);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

And my JS client setup running on the latest version available on NPMCDN:

Parse.initialize(APP_ID);
Parse.serverURL = 'http://localhost/parse';
var query = new Parse.Query('Sale');
query.equalTo('status','pending');
var subscription = await query.subscribe();

subscription.on('open', () => {
    console.log('subscription opened');
});

subscription.on('create', (object) => {
    console.log('object created',object);
});

subscription.on('update', (object) => {
    console.log('object updated',object);
});

Any ideas?

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..??

yyman001 commented 4 days ago

guys , I m facing the same , only OPEN event works, others events doesn't work..伙计们,我面临着同样的问题,只有 OPEN 事件有效,其他事件不起作用..

This is probably because you did not add it to liveQuery: { classNames: [...] } in the server.这可能是因为你没有将其添加到 liveQuery: { classNames: [...] } 在服务器中。

how about use live query in docker compose config ? this is s my config

  parse-server:
    depends_on:
      - mongodb
    image: parseplatform/parse-server:latest
    container_name: parse-server
    networks:
      mynetwork:
        ipv4_address: 172.18.1.101
    ports:
      - "1337:1337"
    restart: always
    environment:
      PARSE_SERVER_APPLICATION_ID: xxxx
      PARSE_SERVER_MASTER_KEY: xxxx
      PARSE_SERVER_DATABASE_URI: mongodb://xxx:yr12H4dLe8wdxF@172.18.1.100:27017/dev?authSource=admin
      PARSE_SERVER_MASTER_KEY_IPS: "0.0.0.0/0"
      PARSE_SERVER_CLOUD: "./cloud/main.js"
      PARSE_SERVER_CORS: true # 启用CORS
      PARSE_SERVER_LIVE_QUERY: true # 启用LiveQuery
      PARSE_SERVER_LIVE_QUERY_SERVER_OPTIONS: '{"classNames":["UserStatus"]}' # 监控类名
      #PARSE_SERVER_CLOUD_CODE_MAIN: "/parse-server/cloud/"
    volumes:
      #- ./config/parse-config.json:/parse-server/config.json
      - ./cloud:/parse-server/cloud
      - ./log:/parse-server/logs