Send android push notification when new doc arrives at sync gateway?


Hi i am developing an android chat app using CBL now i need to send push notification(using Google Cloud Messaging) to user when new chat message(doc) arrives at couchbase db through sync gateway how i can do this ?


Hi @psrinivasgoud,

You can get Replicator’s change event through Replicator ChangeListener.

If you’d like to know which document is updated, please use Database ChangeListener.

I hope this helps you.



HI @hideki thanks for reply . this for client side right i added addChangeListener to database but its working only when app is running when i closed app its not working (even tried with android service) that why i need server side listener.


Hello @psrinivasgoud,

There are two options for making sure client applications have the latest data from sync gateway (in this case, chat messages):

  • use a continuous pull replication
  • use push notifications from the server as you mentioned. Check out the Changes Worker Pattern guide You can use (or the equivalent module in the back-end language of your choice) to listen to the changes feed of Sync Gateway (it’s the same api as CouchDB so any changes feed listener module for CouchDB will work with Sync Gateway too). Whenever a message type document is received by Sync Gateway, you can catch this change in the changes feed and then get the user profile documents which may contain the device token(s) to send the push notifications to (there are lots of modules for sending notifications as well. For example



Hi @psrinivasgoud,

You can also check out this blog post on using push notifications with Couchbase Mobile

In this case, the wakeful service executes the pull replication regardless of whether the app is opened or closed.



Thanks a lot @jamiltz


Hi team . How sync_gateway can be configured to send new data to firebase cloud message fcm. I want every time sync gateway get new object it sends it to fcm and fcm handle the push notification to the device with couchbase lite.