Does anybody have specifics on how to connect an Android application to MongoDB running on Azure roles?
--
Hi, I have MongoDB replica set running on multiple Azure roles in the Cloud Service. I have used the mongo-azure library on GitHub to create the role instances and have them running in Azure.
Most articles online seem to only talk about connecting to Azure-MongoDB locally (via localhost). But, since my application won't be running locally to Azure, I feel that I have to use REST to somehow connect to Azure cloud servers, which may or may not propagate data to the MongoDB replica set.
Does anybody have more specifics on how to connect an Android application to MongoDB running on Azure roles?
(Or, for those that don't have experience with Android/Java: how to connect from non-localhost using non-.NET?)
ps - In other MongoDB questions, people have already answered Android is not natively support by MongoDB, and using non-native methods is fine by me. There are apps out there that already do this, mainly Foursquare. Unfortunately, they use AWS instead of Azure (the requirement for me).
pps - if anybody has any more resources for the linked mongo-library about how it works in more detailed terms, then that would be very helpful too.
UPDATE:
I found the most up-to-date version of mongo-java-driver.jar (currently 2.11.3) and am testing that.
Thanks to another question I've found the particular issue with Android not supported by the java driver, but that issue appears to be resolved.
Possible Solution:
In the Visual Studio project, I created an Input Endpoint for the role. So far that seems to do the trick, using MongoClient mongo = new MongoClient("<my_ip_address>", 27017);
Your 'possible solution' is the right one in my view - you need to open a (load balanced) TCP port in the firewall surrounding your roles and InputEndpoint is the way to do that.
You cannot use an input endpoint if you are doing writes when using a replica set of size > 1 if you are the github solution above. You do not want the Azure load balancer to route a write (insert or update) to a secondary of MongoDB in which case your write will fail.
If you use Azure virtual machines then you can create a port mapping per virtual machine instance and overcome this.
Related
I am trying to access Azure SQL Database , using java. Our code will be staying in MS Appcenter. Since the DB firewall is not letting the Appcenter to access the database, I am trying to use API. Can someone help me provide me steps / sample code to get it started?
You will need to enable firewall of Azure SQL Database to allow
connection from azure (as you are hosting it in the MS Appcenter).
In order to do that read document
Once that is enabled, you can use documentation Quickstart to see how you can connect from it from application. Above document is in java language but you can find similar document for other languages also.
can someone help me with any sample working code or any project that I can look at? I have been searching this on google for few days but I always end up an answer with spring boot but I need to connect without using spring boot. I need to write automated API tests where I have to connect to cloud Sql fetch the data from Db and validate it.
As #siamsot mentioned, there is an article in the official GCP documentation on how to connect to a Cloud SQL instance.
Basically, you have the following options to connect to a Cloud SQL instance:
By using the proxy (Second Generation instances only)
By configuring access for one or more public IP addresses
By using the JDBC Socket Factory (for the Java programming language,
Second Generation instances only)
By using the Cloud SQL Proxy library (for the Go programming language, Second Generation instances only)
I have developed a REST web-service in Java interacting with a MySQL database.I want to deploy the web-service and the create a database at a server so that I can invoke it from an application.I tried Microsoft Azure but was unable to get it done.Where can I find relevant information for this?
I had similar problems with a MySQL database using the third party option in the Azure Marketplace from ClearDb. What I ended up doing was switching my database from a MySQL instance to an Azure Database Instance (Subset of SQL Server's features.) This worked perfectly for me! I was able to query from my database feed data to my api, and access the API through my Azure Web App.
I understand this may not be an option for you, however, Digital Ocean is a great cloud hosting option (with scaling similar to Azure, although not as good in my honest opinion.) You can set up a Linux Environment with a MySQL Server and JVM and serve your whole API through there. Best of Luck!
#coderden, According to your description, I think you have been deployed your Java Application on an Azure WebApp. Then when you created a MySQL database on Azure for connection from the Java webapp, please make sure the webapp & mysql instance created in a same resource group and note the connection string of MySQL on Azure.
As reference, please see the article to try again although it's for PHP, the steps are the same for Java.
I have built a mobile application that needs to connect to my SpringBoot-WebApp which in turn has a MongoDB and some other things in the background.
I want to deploy this WebApp at Amazon AWS, but I am overwhelmed by all the possibilities. So far, I have just created it as a .jar, and ran it that way, and it worked fine at my other server.
Now, for traffic reasons and such, we want to move it to AWS. I have found out, that I need to create a .war instead of a .jar, which is not a problem. I then learned to upload this .war to Elastic Beanstalk. However, my application needs to connect to a MongoDB. I have logged on to AWS via SSH and installed MongoDB there and created the database, but it does not seem like this is the right way to do it.
It'd greatly appreciate if anyone could give me a hint on how to do this as I am very confused.
Thanks and best regards!
It isn't clear if you are doing this, but don't run MongoDB on Elastic Beanstalk. The Elastic Beanstalk server you have it installed on may be automatically deleted by AWS. In general you do not want to manually install anything on Elastic Beanstalk as it is a managed environment where servers may be automatically created or deleted based on server load.
Amazon doesn't provide a MongoDB service directly, so you either need to install and manage MongoDB on an EC2 instance (or fleet of instances) yourself, or use a third party MongoDB service that runs on AWS. You could use something like MongoLab which provides a MongoDB service that runs on AWS. This allows your network traffic between your web servers and database servers to stay within the AWS network, which you will want for both performance and security reasons.
If you use MongoLab just make sure you choose to create your database in the same AWS region that you are deploying your application to. Also, I wouldn't recommend their free sandbox databases for any sort of critical production application.
If you decide to install and manage MongoDB on AWS yourself, here is some documentation from Amazon, and some from MongoDB.
I've created a web application in Java with Google Web Toolkit (GWT). On the client side, GWT generates an input box and (using the GWT search api) conducts a web search. I'd like to push some of the information from the web search into a MySQL database so that it can be analysed using a machine learning application (Weka). I've got an RPC running that interacts with server side code. In that server side code, I tried to establish a connection to the MySQL database.
I'm currently running the project locally, so, as far as I can tell, google app engine is hosting it. This is supported by the fact that when I run the application I get the following message:
Initializing AppEngine server
Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
The server is running at http://localhost:8888/
However, although I'm able to use the search part of the application, it throws an exception when trying to connect with my MySql database.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission mysql.database.location resolve)
I've tested the database connection from a regular (non-web based) Java program and there's no problem connecting to it from outside of the web application. I believe that I'm getting this error because google app engine won't allow connections to outside databases.
In short my questions are:
1. Although I'm using Google App Engine, is it possible to use a server side code to connect to MySQL? (I'm assuming no, but this would be ideal).
2. Is it possible to switch to another server (like Tomcat)? If so, can anyone point me to references about how to do this? I found an old stackoverflow question about how to use tomcat (http://stackoverflow.com/questions/2208181/gwt-app-deploying-on-tomcat-or-any-other-servlet-container) but it no longer directs to a place that has information about using other servers.
Thanks for your help and please feel free to ask follow up questions if you'd like me to provide more info.
GAE disallow any access to other servers. You can use URLFetch service, but it's probably not what you want, and you cant use it for MySQL connection. BTW, you can create your own, http based protocol, for interacting with your other modules, but it's may be too complicated.
GWT compiles to javascript, and it works only on client-side, so it' doesn't matter what you're using on your server side, it could be used any programming language and any webserver (remember that you can use JSON to communicate, instead of default protocol). It's just default implementation of RPC build using java servlets, and you can use it inside any java web container, including tomcat. GWT was developed few years before GAE, it's totally independent projects, and it isn't requires to use GAE for server side.