parse-community / parse-server

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

Live query not working #7475

Open cosmicdust471 opened 3 years ago

cosmicdust471 commented 3 years ago

New Issue Checklist

Issue Description

I'm facing an issue with live queries. The client receives the "open" event but doesn't receive the "create" or "update" events.

Server setup:

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

Client setup:

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

Environment

"axios": "^0.21.1",
"body-parser": "^1.19.0",
"card-validator": "^8.1.1",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"coordenadas-do-cep": "^1.2.0",
"ejs": "^3.1.5",
"excel4node": "^1.7.2",
"express": "^4.17.1",
"express-device": "^0.4.2",
"fs": "0.0.1-security",
"http": "0.0.1-security",
"https": "^1.0.0",
"image-search-google": "^1.3.0",
"parse-dashboard": "^2.1.0",
"parse-server": "^4.5.0",
"path": "^0.12.7",
"request": "^2.88.2",
"serve-favicon": "^2.5.0",
"shelljs": "^0.8.4"

Server

Database

Client

Logs

info: Create new client: 3e332475-fabe-488c-9a9c-fd6b69cc3ce6

mtrezza commented 3 years ago

Thanks for reporting. Can you try to reproduce this in a PR with a failing test?

cosmicdust471 commented 3 years ago

I think my problem is with scalability. I'm running my parse server on multiple cores so how would I go on about doing this?

I've created a redis server on my local machine running on port :6379

Server:

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'],
        redisURL: 'redis://localhost:6379'
    }
}));

var httpServer = require('http').createServer(app);
httpServer.listen(80);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer,{
    redisURL: 'redis://localhost:6379'
});

Client:

Parse.initialize(APP_ID);
Parse.serverURL = 'http://localhost/parse';

However I only receive events when running in single core. Am I missing something?

mtrezza commented 2 years ago

I'm closing this as it does not seem to be a Parse Server issue.

For help with Parse Server, here are some resources you can try:

Feel free to comment if you have any questions and we can re-open this issue.

ckarmy commented 2 years ago

@franalt you resolve this issue? I have the same problem with pm2 cluster mode

MaidaShahid commented 1 year ago

@franalt How did you resolve this issue? "I'm facing an issue with live queries. The client receives the "open" event but doesn't receive the "create" or "update" events."

I'm facing the same issue.. is there a solution without the redis server?

MaidaShahid commented 1 year ago

@ckarmy were you able to resolve your issue?

ckarmy commented 1 year ago

@ckarmy were you able to resolve your issue?

No :( I couldn't figure out how to make it work!

mtrezza commented 1 year ago

Is it the same issue as in the description? If so, we can re-open the issue, otherwise please open a new issue.

MaidaShahid commented 1 year ago

@mtrezza Yes, its the same issue.. kindly reopen it..

MaidaShahid commented 1 year ago

Is it the same issue as in the description? If so, we can re-open the issue, otherwise please open a new issue.

i even tried with redis server to scale it. but i got the same issue. i'm able to trigger the subscription open event. But the subscription create, update, delete etc events are not triggered..

MaidaShahid commented 1 year ago

@ckarmy were you able to resolve your issue?

No :( I couldn't figure out how to make it work!

So, what was the work around that you did, instead of using live query..?? Kindly can you tell..

parse-github-assistant[bot] commented 1 year ago

Thanks for opening this issue!

mtrezza commented 1 year ago

It is the exact same issue as posted originally?

The client receives the "open" event but doesn't receive the "create" or "update" events.

keanallen commented 1 year ago

Hi, I got my LiveQuery working:

var express = require('express')
const { default: ParseServer, ParseGraphQLServer, RedisCacheAdapter } = require('parse-server');

const redisURL = process.env.REDIS_URL
const liveQueryCollection = ["Your","Classes","Goes","Here"]

var redisOptions = { url: redisURL }
var redisCache = new RedisCacheAdapter(redisOptions)

var api = new ParseServer({
    ...
    ...
    cacheAdapter: redisCache,
    liveQuery: {
        classNames: liveQueryCollection,
        redisURL: redisURL,
    },
     rateLimit: {
        requestPath: '*',
        requestTimeWindow: 10 * 60 * 1000,
        requestCount: 5,
        errorResponseMessage: "Too many requests. Try again after 10 minutes.",
        redisUrl: redisURL
    }
})

// Start the parse
api.start()

...
...
...

// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer, {
    redisURL: redisURL
})

Parse version: 6.1.0

However, I got a log saying: error: Could not connect to redisURL in rate limit: Error: Socket already opened

mtrezza commented 1 year ago

@keanallen This issue only happens if you use LiveQuery with redis, otherwise it works fine?