Choosing a Platform for a new microservice

Microservices endorses using different technologies to build components of a solution or a system. You can have components based on Java or Scala with Spring or C# & .Net etc. But if you are going to build a new microservice which platform should you use? Most developer’s or architects would choose based on their background if they came from Java they choose Java or .net if they are from .net. This kind of reminds me of an old Dilbert comic in it Dilbert tells the marketing manager that he can draw a fish on the screen. It sounds to me like most architects choose a platform because they are familiar with not because of its merits. I am working on devising a decision tree to select which platform is more suitable for a microservices. So far if you are building a microservice to interact with Hadoop/Spark or Kafka Java/Scala/Spring is the platform to go, though there are lots of libraries that makes it easy to develop such microservices in .Net. I am still working on this but thought I should share it. Let me know your thoughts and why would you choose a platform over the other?

Java Scala /Spring MVC

  • Pros:

    • Respected in the business
    • Widespread
    • Constrained coding style might lead to easier to read code
    • Better ecosystem for libraries and tools
  • Cons:
    • Verbose, both with the language and framework
    • Does not have as good support for threading and asynchrony as C# has with async/await

C#/ASP.NET Core

  • Pros:
    • Asynchronous -oriented
    • Better generics, and integration with LINQ
    • Better IDE integration, and configuration setup
    • Quicker to get things up and running in
    • Able to be component oriented as well as MVC
    • Availability of other programming styles than OOP, including functional.
    • More low-level constructs allowing optimization
  • Cons:
    • Newer, slightly buggy
    • Not as battle-tested as Java
    • Heavy IDE (although you can use Visual Studio Code, too)
Advertisements

Itinerary Configurator

Problem

I had many web services to implement with BizTalk ESB Toolkit. All these web service would take input message, perform some mapping/enrichment on the input message call a web service on a LOB system. The LOB web service result would then be mapped to the result of the web service and returned to the caller.

Figure 1: Web service implemented as an Itinerary

If you look at and web service implemented as an itinerary if would look as in figure 1. The itinerary consists of:

  1. A two way on ramp that receives the message
  2. A call to a map to prepare the LOB web service message request
  3. A rout to the LOB web service send port
  4. Call the LOB web service through the send port
  5. Map the response from the LOB web service to the web service schema response
  6. Route the response to the two way receive location through the on ramp

Now I need to implement more than 50 web services that would be performing the same logic except for a different maps to transform to different LOB web service and a different send port for each LOB web service. I can create an itinerary for each web service but that would lead a numerous number of itineraries with the same structure. So I wanted to create a Kind of an itinerary template for all these services. Let us first examine in more detail how an Itinerary implements a web service.

Implementing a Web Service with and ESB Itinerary

For simplicity assume I want to implement a simple web service with BizTalk ESB toolkit that would take as input two number, call a web service that would perform addition or other mathematical operation on them and then return the result to the caller.

The first step is to define the schemas for the request, response in a BizTalk Project. Use the BizTalk WCF Service Publishing wizard to publish a two way web service with request that takes the request schema and a response with the defined schema.

Second step is to start a new blank itinerary and add an onramp service, and configure it to be the receive port defined step 1. You will also need to change the receive location pipelines to be the ESB Toolkit pipelines Itinerary select Receive XML for the receive pipeline and Itinerary Send Pass through for the send pipeline

Create a SQL Database Programmatically

In this article I will explain how to use MS SQL Management Objects (SMO) to create a MS SQL database from C# code. In this sample will

  1. Enumerate all the SQL servers in the network and fill a list box where the user can select one of the servers.
  2. The user will enter the Database Name to create.
  3. The user will enter an AD account to grant right to.
  4. When the user click “Create Database” the system will check for the existence of the database.


Background

SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server. You can use SMO to build customized SQL Server management applications. Although SQL Server Management Studio is a powerful and extensive application for managing SQL Server, there might be times when you would be better served by an SMO application.

Enumerating SQL Servers

The  SmoApplication.EnumAvailableSqlServers() enumerates a list of available instances of Microsoft SQL Server. it returns a Datable object value that contains an enumerated list of information about the available instances of SQL Server. The table describe the different columns of the returned DataTable.

Column Data type Description
Name
String The name of the instance of SQL Server.
Server
String
The name of the server on which the instance of SQL Server is installed.
Instance
String
The instance of SQL Server.
IsClustered
Boolean A Boolean value that is true if the instance is participating in failover clustering, or false if it is not.
Version
String
The version of the instance of SQL Server.
IsLocal
Boolean
A Boolean value that is true if the instance is local, or false if the instance is remote.

The computer running the instance SQL Server might not receive responses to the EnumAvailableSqlServers method in a timely manner. The returned list might not show all the available instances of SQL Server on the network. When you call the EnumAvailableSqlServers method in subsequent tries, more servers might become visible on the network.

MessageBox.Show(“Going to look for all SQL Server in the network this might take some time. Do you want to proceed”, “SQL Servers”, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)DataTable dt = SmoApplication.EnumAvailableSqlServers();foreach (DataRow dr in dt.Rows)this.cbServers.Items.Add(dr[0]);

Connecting to SSQL Server

First we check if the user selected the local server or a  SQL serevr

//Connect to the local, default instance of SQL Server.

string srvname = this.cbServers.SelectedItem as
string;

Server srv;

if (srvname == null)

{

srv = new
Server();

sb.AppendLine(“Connected to local SQL server”);

}

else

 {

srv = new
Server(srvname);

sb.AppendLine(string.Format(“Connected to 01908433-d6b4-4413-939a-d55d1e4ee364”, srvname));

}

Checking if the Database Exists

It is easy to check if the database already exists or not, just use the Databases attribute of the server as follows

//Define a Database object variable by supplying the server and the database name arguments in the constructor.

 Database db = srv.Databases[this.tbDBName.Text.Trim()];

if (db != null)

{

if (MessageBox.Show(string.Format(“The ‘01908433-d6b4-4413-939a-d55d1e4ee364’ already exists do you want to drop it?”, this.tbDBName.Text), “Warning”, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)else

{

db.Drop();

}

 {

if (MessageBox.Show(string.Format(“Create the Tables and Stored Procedures for BT Error Manager on ‘01908433-d6b4-4413-939a-d55d1e4ee364’?”, this.tbDBName.Text), “Warning”, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

{

sb.AppendLine(“Creating the Tables and Stored Procedures.”);

this.tbProgress.Text = sb.ToString();

db.ExecuteNonQuery(dbstring);

sb.AppendLine(string.Format(“Created the Tables and Stored Procedures for BT Error Manager on ‘01908433-d6b4-4413-939a-d55d1e4ee364′”, this.tbDBName.Text));this.tbProgress.Text = sb.ToString();this.tbProgress.ScrollToCaret();“Proceed or select another database”);this.tbProgress.Text = sb.ToString();this.tbProgress.ScrollToCaret();return;

}

sb.AppendLine(

}

}

Creating the Database

To create a database all you have to do is create a new Database object with the Server and the Name of the database then call the Create Method.

db = new
Database(srv, this.tbDBName.Text);

this.tbProgress.Text = sb.ToString();

this.tbProgress.ScrollToCaret();//Create the database on the instance of SQL Server.

db.Create();

sb.AppendLine(“Created the database.”);

sb.AppendLine(“Creating the Tables and Stored Procedures.”);

this.tbProgress.Text = sb.ToString();this.tbProgress.ScrollToCaret();

Running the SQL Script

The last step is to run the script that will create the tables, views , stored procedures etc.

//’Reference the database and display the date when it was created.

 db.ExecuteNonQuery(dbstring);

Notes

If you want to use this code in your project, you will need to add references to the SMO assemblies. You can locate the SMO assemblies in the C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder. Select the following files:

  • Microsoft.SqlServer.ConnectionInfo.dll
  • Microsoft.SqlServer.Smo.dll
  •  Microsoft.SqlServer.SqlEnum.dll
  • Microsoft.SqlServer.SmoEnum.dll