# Live Query doesn't work?

**URL:** <https://community.parseplatform.org/t/live-query-doesnt-work/1350>\
**Category:** Android Live Query SDK\
**Tags:** live-query\
**Created:** [February 21, 2021, 8:02pm UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350 "2021-02-21T20:02:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [February 21, 2021, 8:02pm UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/1 "2021-02-21T20:02:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 22, 2021, 7:29am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/2 "2021-02-22T07:29:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [February 22, 2021, 7:29am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/3 "2021-02-22T07:29:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 22, 2021, 7:45am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/4 "2021-02-22T07:45:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 22, 2021, 7:47am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/5 "2021-02-22T07:47:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 22, 2021, 7:47am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/6 "2021-02-22T07:47:52Z")

</div>

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](https://docs.parseplatform.org/parse-server/guide/#scalability)

---

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [February 22, 2021, 7:56am UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/7 "2021-02-22T07:56:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 22, 2021, 9:17pm UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/8 "2021-02-22T21:17:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![uzaysan](https://community.parseplatform.org/user_avatar/community.parseplatform.org/uzaysan/32/59_2.png) [@uzaysan](https://community.parseplatform.org/u/uzaysan)\
**Post date:** [February 22, 2021, 9:33pm UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/9 "2021-02-22T21:33:07Z")

</div>

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

```
liveQuery: {
    classNames: ['Message'],
    redisURL: 'redis://username:pass@ws-redis.example.com: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.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [February 24, 2021, 7:10pm UTC](https://community.parseplatform.org/t/live-query-doesnt-work/1350/10 "2021-02-24T19:10:03Z")

</div>

Yes. That’s the idea.
