Couchbase server and Android - android

It's possible to connect an Android application directly to a Couchbase server database?.
It's possible to get a Document from Couchbase's bucket and use it from an Android application?.
Thank you.

tl;dr: Use Sync Gateway.
Couchbase Sync Gateway is designed to be a web edge service that you use to access data. In the most typical scenario Sync Gateway connects to a back end Couchbase Server cluster.
You could in theory use one of the client libraries to access Couchbase Server directly. You really don't want to do this for several reasons.
The client libraries have different expectations around network latency and availability.
They don't currently (as of Couchbase Mobile 1.4) support the meta data needed for syncing.
You'd need to expose your server which raises your security risk profile
The system architecture has all this in mind, which is why it's designed the way it is.

Related

Connecting Android Application to MySQL Database hosted on AWS

Good day everyone,
I have developed an android application and I would like to store my business information on MySQL database. I have decided to use amazon services for this project however I'm very confused how to allow my application to establish a proper/secure connection with MySQL database in order to pull and push the information into it. I have read many articles/stack overflow posts and realized I have to deploy a REST api in order to provide a layer between the application and the actual database. However with AWS being very confusing, in my opinion, i'm super lost.
Could any of you gentle folks provided with the step-by-step guide what services to use, how to connect them together and deploy them in order to be able to use it in my android application. Or maybe an article describing the steps? I don't really need a detailed explanation just a nudge in the right direction and I will try to figure out the rest.
Thank you greatly.
First of all, connecting to MySQL directly from an Android application is not secure, since you need the MySQL database access credentials for the app to communicate with the database.
This is why people recommend using a REST API Layer in between the MySQL database which you can implement using API Gateway and Lambda. This can be secured using a strong authentication mechanism for the API and using SSL for encrypting the messages at Transit.
However, this is not the case if you plan to connect to AWS DynamoDB from Android App. You can enforce Fine-Grained Access Permission to DynamoDB tables and roles using IAM policies.
Few Tutorials that might help,
Serverless REST API in Minutes with Serverless Framework.
Querying RDS MySQL with NodeJS Lambda Function.
Using Mobile Hub (To Simplify Things).
User Authentication with Cognito UserPools.

Couchbase Lite and CouchDb

I've built an Android app based on Couchbase Lite which talks to a Couchbase Database via Sync Gateway. I've now tried to get Couchbase Lite to replicate with a CouchDB 2.0 database, but I am getting the following error:
W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {POST,
http://192.168.1.5:5984/_revs_diff}: Got error status: 404 for
http://192.168.1.5:5984/_revs_diff. Reason: Object Not Found
W/Sync: PusherInternal{http://192.168.1.5:5984, push, 12ff9}: Progress:
set error =com.couchbase.lite.replicator.RemoteRequestResponseException:
Object Not Found
Note that for this I am not going through Sync Gateway but rather point Couchbase Lite directly to the CouchDB Url.
I don't know whether I need to go through Sync Gateway or not, but my impression after reading the Couchbase docs on Couchbase lite is that I do not when connecting to a CouchDb database and this post seems to back that up. https://github.com/couchbase/sync_gateway/issues/312
Can someone please confirm whether it is possible for couchbase lite to replicate directly with a CouchDb 2.0 database and if so what is the correct way to set it up?
Also, the app will be used by many sites, a site can be made up of one or more users. The reason I was thinking switching to CouchDb is so that I can have one database per site, something which doesn't seem to be easily doable in Couchbase. However, I have now discovered Channels in Couchbase which allow me to use one database but keep access to documents restricted by site (i.e. a site could have many users and all users should have access to all documents for that site).
What would be the pros and cons of using either separate databases in CouchDb or channels in Couchbase?
Thanks.
As #Hod said different buckets is equivalent to different databases in Couch DB so you can go for that.
Secondly it is definitely encouraged to use sync_gateway's channels property if you can because creating single bucket is preferred over multiple buckets and I have used sync_gateway with couch Lite and Couch server, it works perfectly fine and also with accuracy so I think you should go with sync_gateway and channels instead of creating multiple buckets
A few points in response:
The main thing is I think you can do what you want easily in Couchbase. Buckets in Couchbase Server are somewhat equivalent to separate databases. So you could split your sites that way. Channels in Sync Gateway give you more control for separating data and controlling access, as you've seen.
Couchbase Lite should be able to sync with CouchDB, but this isn't heavily tested. It's hard to tell from your snippet what's going wrong. You might check this post for some ideas: CouchDB: how to use _revs_diff to get document revision ID
Sync Gateway exposes a sort of superset of the CouchDB replication endpoints, so you'll have more flexibility using Couchbase Lite with Sync Gateway.

Connecting Android to AWS RDS [duplicate]

Background
I have a EC2 instance with a RDS instance(MYSQL) associated with it.
I want to use a android app to execute queries on that MYSQL instance.The Android sdk of amazon does not support RDS.
Problem
How do I connect my android app with RDS instance?Is it possible to use RDS(MYSQL) with an android application without sdk support?
RDS is not a database engine. It's a service that manages the infrastructure for you that's required to maintain a highly available and fault tolerant database. It supports a number of different engines such as MySQL as you mentioned. Please read the docs for more information.
You need to connect to your RDS MySQL instance the same way you would connect to any MySQL database. Using a library that supports MySQL, and using the hostname, username and password for your database.
However, it's probably not the best design to have phone clients connecting to your database remotely. The best thing to do would be to put a REST API on AWS that interfaces with your database.
Having n users connected to your database from each handset using your app is probably a bad idea. It means you need to have more power in your database, greatly hinders your scalability and makes things less secure as the database is exposed to the internet. With an API in front of it, you can build a much more fault tolerant, scalable and solution.
The "cloud way" to build mobile apps is to (within reason) build your application logic on the cloud and simply have your client code connect to your API. This way you can spread to more platforms (eg. IOS, Web) much more easily as you won't have to manage separate application level code for each platform. You'll just need to manage code that integrates with your already existing API.
Take a look at this whitepaper. Ignore the web server tier and focus on the App Server and Database tiers. This is probably the best design to go by.

Using Amazon RDS with android application

Background
I have a EC2 instance with a RDS instance(MYSQL) associated with it.
I want to use a android app to execute queries on that MYSQL instance.The Android sdk of amazon does not support RDS.
Problem
How do I connect my android app with RDS instance?Is it possible to use RDS(MYSQL) with an android application without sdk support?
RDS is not a database engine. It's a service that manages the infrastructure for you that's required to maintain a highly available and fault tolerant database. It supports a number of different engines such as MySQL as you mentioned. Please read the docs for more information.
You need to connect to your RDS MySQL instance the same way you would connect to any MySQL database. Using a library that supports MySQL, and using the hostname, username and password for your database.
However, it's probably not the best design to have phone clients connecting to your database remotely. The best thing to do would be to put a REST API on AWS that interfaces with your database.
Having n users connected to your database from each handset using your app is probably a bad idea. It means you need to have more power in your database, greatly hinders your scalability and makes things less secure as the database is exposed to the internet. With an API in front of it, you can build a much more fault tolerant, scalable and solution.
The "cloud way" to build mobile apps is to (within reason) build your application logic on the cloud and simply have your client code connect to your API. This way you can spread to more platforms (eg. IOS, Web) much more easily as you won't have to manage separate application level code for each platform. You'll just need to manage code that integrates with your already existing API.
Take a look at this whitepaper. Ignore the web server tier and focus on the App Server and Database tiers. This is probably the best design to go by.

What should I use as a server to meet the following requirements?

I am trying to develop a system that involves a:
server with a database that will handle the system's logic and manipulate data
an android app that will interact with that server (pull and push data into the server)
a website that will do the same as the android app, but from a website with slightly different data.
What I thought of is to use SQLite with Apache Tomcat installed on the server and deploy a Grails war file on it. That will take care of the 'website' side of the system. But what about the android app? Can it communicate with Tomcat as well?
Tomcat will suit your needs. I would look at hosting options though. Are you hosting your own server, or do you have a hosting provider? Do you have experience hosting a tomcat server etc. Do you have experience with java web applications, or other web frameworks? All of the above, and probably more should lead you to your decision on what type of framework/language to use on the server. This in turn will lead you to your options for hosting, and web-container to use.
Once that is determined all major web frameworks will allow you to publish web-services Rest, Soap, etc. that can be consumed by an android application.
Also, if you are planning on providing a web interface and service at the server level, my guess is you are going to be storing a fair amount of data, I would look into a more robust and scalable database such as mysql or postgres. This post contains some insights into this.
If you have an API that is web accessible, an Android can access it.
Android shouldn't have any problems communicating with Tomcat.
Look at http://grails.org/doc/latest/guide/13.%20Web%20Services.html for more information.
A RESTful web service is most likely what you'll need. Android can consume SOAP web services but it requires more work for less overall functionality.

Categories

Resources