Following up from the first blog post, let’s continue with Endpoint configuration and some .NET code to test the connection to the Couchbase node.
Endpoint Configuration, what is that exactly?
By default, Azure blocks most external connections to the Virtual Machine (VM). The default exceptions are PowerShell (port: 5986) and Remote Desktop (port: 59548).
Connection attempts to other ports are blocked by Azure Endpoint Protection, unless they are added to Endpoint Protection as a “pass through”. You can think of Endpoint protection as a “Cloud Firewall” or perhaps port forwarding in a DMZ Zone.
Regardless, all ports used by the Couchbase Client need to be added to the Endpoint protection to allow the the client and node to communicate.
The complete port list for Couchbase Server/Client can be found here:
Please note the Client/server (“yes/no”) header.
No need to open more ports then the client is using/needs.
In this sample/demo we will not use SSL and therefore there is no need to open port 11207 as this is only used for SSL etc.
The ports that we need to add to Endpoint Protection for the .NET Client to connect to the node are:
8091 – Web Admin
8092 – API
11210 – Bucket (no SSL)
Note: If you are planning to use N1QL (SQL for Documents) you also need to add port 8093!
Endpoint Configuration, adding the ports
Go to https://manage.windowsazure.com
and navigate to the Virtual Machine created in “part 1”.
Hit the “Add” button and follow the on screen guide to add the 3 ports to the Endpoint Configuration.
In the current Azure Portal can only add a single port at a time, this is a bit time consuming and will hopefully change in the future.
As part of the Endpoint Configuration we added port 8091, the Couchbase Server Console.
You should now see the Couchbase Console login page. If you get a “timeout” or “unknown page” error, then please check that the Couchbase Server is running and port 8091 has been successfully added to the Endpoint Configuration.
Assuming that everything went as planned and the browser showed the Couchbase Console Login page, let’s continue to build a .NET Client to connect to the Node.
The .NET SDK – Building a test Client with .NET
The Official .NET SDK for Couchbase is open source and can be downloaded, edited, changed etc. from Github, https://github.com/couchbase/couchbase-net-client
For convenience the SDK is also avaliable on Nuget, https://www.nuget.org/packages/CouchbaseNetClient/
With the SDK easy at hand, the only step missing is coding a small test project.
Open Visual Studio and create a new Console app.
Right click the Solution in Solution Explorer and click Manage Nuget Packages for this Solution.
Search for “Couchbase SDK” and install the package as shown on the picture below.
Depending on network speed, the package download + dependencies can take some time.
Couchbase SDK uses “System.Configuration” as part of the configuration and setting up the connection uris in code. Therefore you will need to add a ref. to this DLL as well.
Now we are ready to do some actual C# code and connect to our one node Couchbase Cluster.
Connecting to the Cluster with the Couchbase .NET SDK!
Open program.cs and replace the existing code with the code below (all code lines):
Please note that you need to update the Server Configuration to point to your own Couchbase Cluster, but with that change done we are ready to run the code.
The Main method is the entry point and the first piece of user code run in the cmd app.
It starts by initializing ClusterHelper, as Singleton with “multi-tons” Bucket references. This is the recommended way to access Bucket’s and Cluster Configuration.
ClusterHelper ensures that there is only one instance of a bucket (thread safe) that can be shared for the lifetime of the application.
You can read more about the details of the code and the Couchbase .NET SDK here.
In part 3 we will scale the Cluster to have multiple nodes within a private virtual network.
Thanks for reading