简体   繁体   中英

Intercepting PouchDB communications with CouchDB backend

I am considering PouchDB & CouchDb as an alternative to Amazon Cognito Sync for a hybrid mobile app that will need data synced between devices and users. I have pouchdb working in a small sample app that syncs with a local couchdb.

I need to be able to intercept the communications back and forth between the pouchdb and couchdb in Java in order to do things in response to these sync events. Sort of like Amazon Cognito Sync's sync triggers. Also, I keep thinking much like Spring's AOP around.

Since the couchdb has a rest interface, I thought I could point the pouchdb to my application server which has a controller listening for any request with the db name as the base. When a request, from pouchdb comes in the Java Rest Controller can optionally do something, then forward the request to the real rest endpoint of the couchdb and get a response, then optionally do something again, then return the response to the pouchdb.

Does this seem like a feasible solution? I am currently working on trying to get this concept working. Has anyone else done anything like this? Any major pitfalls to this approach? Currently, I'm using Java 8 with Spring Boot & Jersey.

I think the architecture goes like this:

  • Data is empty everywhere.
  • Data changes, the device where the data changed pushes via a REST APIs.
  • Your server "master", send notification GCM or APN to devices.
  • In your notification listener, you check the type of notification and you sync the data.
  • If a new device connects to your "list of devices to sync" you send a push notification to sync the data.
  • Keep a list of connected devices.

The same ideas goes for every device/web browser. You have a local cache that you push to the "master" if it changes locally.

You will have many cases to deal with, and I don't think there are open source projects that offers the same patter as Cognito Sync.

Also think about scalability, devices don't have to pull your "master", the master sends notification to trigger devices to download the data.

You have to deal with diffs, regular checks, and so on ... Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM