MonSub is project which allows Android client to setup a chat functionality in few lines of code. It basically uses the capped collection abilities of Mongo and have a cursor act as message notifcation.
A demo application is provided as the sample which uses monsub interface.
- Copy com.anuj.monsub package into your project
- Copy the mongo-java-driver-3.2.0-SNAPHOT.jar into your lib directory
- Update you gradle file to import that jar, look at the sample for example
- Create heroku account and start-up the instance
- Heroku come up with free 2GB of mongoLab, use that for your testing
- You would need database name and URL for mongo
- The sess1 and sess2 is the sample can be anything specify to your application, think as if unique name between the two clients
- If you need to use your own custom object to be persisted in mongo, make sure it extends BasicDBObject look at the sample for detail
register(): register your unique name with the mongo
open() : open will give you any message receiving on the channel
send(): this is used to send the messgae on the channel, which inturn will be publish to different clients
- close functionality which will close all the ongoing connection for the client
- Extend it for more then 2 more person chat
Notes:
- Please check the library I added in the lib folder it's wrapper around mongo java driver to get rid of ssl which is required by heroku