Live Query doesn't work?

I’m trying to setup live query into my app. I created a seperate server for live query. I enabled live query for my classes like this:

liveQuery: {
    classNames: ['Chat', 'Message']
  }

I’m using android SDK. Here is the code I use:

parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI("ws://ws-server.example.com:1337/parse"));
            ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
            parseQuery.whereEqualTo("chat",chat);

            SubscriptionHandling<Message> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
            subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<Message>() {
                @Override
                public void onEvent(ParseQuery<Message> query, Message object) {
                    Log.e("LiveQuery",object.toString());
                    //Other logic
                }
            });

But I dont get live events. I can see in my parse server I connected succesfully. I get this message on console: Create new client: 0a8c1cf4-a0e2-42cb-a8d2-0ea8a17b4988 But ı dont get anything. I cant see my log.

Here is live query log:

V/ParseLiveQueryClient: Socket opened
V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":"aeff6f06-15b7-4102-bfe0-6b7d079dc0f6"}
V/ParseLiveQueryClient: Connected, sending pending subscription
V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":"aeff6f06-15b7-4102-bfe0-6b7d079dc0f6","requestId":1}

Objects has proper ACLs. I can read the objects that matches live query.

Whats the problem here?

How are you creating the objects to test the live query? I ask that because there is a difference between CREATE and ENTER event and sometimes people are expecting the CREATE event to fire while the ENTER is the one firing. Because of that, I recommend you subscribe to all events at least in the first time so you can better understand them.

I tried that also. But didnt worked. I created object from different device. I cloned object from dashboard. But I cant get events

On android studio, I can see I connected succesfully:

V/ParseLiveQueryClient: Socket opened
V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":"aeff6f06-15b7-4102-bfe0-6b7d079dc0f6"}
V/ParseLiveQueryClient: Connected, sending pending subscription
V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":"aeff6f06-15b7-4102-bfe0-6b7d079dc0f6","requestId":1}

I tried subscribing all events like this:

SubscriptionHandling<Message> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
            subscriptionHandling.handleEvents(new SubscriptionHandling.HandleEventsCallback<Message>() {
                @Override
                public void onEvents(ParseQuery<Message> query, SubscriptionHandling.Event event, Message object) {
                    Log.e("liveQuery", "live event");
                }
            });

Still I dont get notified.

You said that you created a separated server for live query, right? So does it mean that your are running parse server in a process and live query in a separate process? That’s probably your problem.

In this scenario you are creating the object in one parse server but waiting the event from other (that do not know that an object was created). There is no communication between them by default.

In order to fix that you will have to setup a redis server and setup live query in both parse servers to something like this: Parse Server Guide | Parse

1 Like

But ıf I have to create liveQuery on my main server, then whats the point o creating new server? Can we do this without opening live query on main server?

I guess I should create liveQuery on both servers. But I guess I can block websockets on my main server by putting it behind of Nginx since Nginx doesnt support ws connections by default? What do you think?

Edit: Ok finally it works. Thank you.

You don’t need to create the live query in both servers, but the one running parse server needs to have the live query configuration so it will be able to properly notify the changes happened through the rest/GraphQL API.

So if I understand correctly I should add this to every server:

liveQuery: {
    classNames: ['Message'],
    redisURL: 'redis://username:[email protected]:6379'
  }

But I add this line to only live query server
ParseServer.createLiveQueryServer(httpServer);

So that means even I dont activate livequery, parse server still uses redis in livequery configuration? Am I right?

Edit: Yes. I disabled live query on other servers. And live query still works. Only passing redis url works. So we don’t have to enable live query on main servers.

Yes. That’s the idea.