Archive

Posts Tagged ‘.NET’

.NET Core Microservices using GeekseatBus

October 22, 2016 3 comments

2016-10-20_12-16-30

GeekseatBus is a simple message bus that can be use to create microservices in .NET.

Here’s the background why we do this on our own.

Background

A lot of microservices right now is in favour using REST API for communication between services. We are in geekseat take different approach for microservices and we avoid request response between services. This is align with SOA tenets for autonomous component. You component can’t be autonomous if you still using request response. If one service dies, other service is dies too. This will create temporal coupling between services.

We are a big fan of Udi Dahan style of microservices. As it enable high cohesion and loose couple on our big system. If you want to learn more you can register for 2 days course for free from here.

The central things from this approach is the needs of message bus. Message bus is used to communicate via fire and forget and also publish and subscribe between each services. So it promotes loosely coupling between each component.

Geekseat has been researching for simple message bus on RabbitMQ. We found NServiceBus and,  Mass Transit. But both of platform can’t be used in Linux. That’s a big problem for us as our backend currently written on .NET Core ( cross platform .net ). So we decide to create our own implementation of Message Bus on top of RabbitMQ.

We has published GeekseatBus to nuget. This is a big first start for us as we are start to open source our infrastructure for microservices.
We are a great believer of keeping thing simple and minimal configuration. As an agile company we like to see our simple stuff works in production. GeekseatBus also rely on convention over configuration. This will made things easier to use.

Getting Started

Ok, Let’s get started. Here’s the schema of what we are going to achieve on this head first with GeekseatBus.

geekseatbus_services

From the above schema we can see that we have 2 services. Order Service and Billing Service. Order Service have 2 component which is Order Client and Order Service ( Server ).

Geekseat.BillingService subscribe to the OrderPlaced event published from OrderService and do it’s own thing by billing the customer according to the product ordered.

Fire and Forget Demo

Now let’s open our beloved Visual Studio IDE.

Create Solution and the .NET core console application for OrderService. This will be OrderService endpoint. This service will handle PlaceOrder command and publish OrderPlaced event.

create_order_services

Add reference to GeekseatBus nuget package to Geekseat.OrderService project.

geekseatbus-nuget

Create class library project for messages. We have 2 messages, PlaceOrder command and OrderPlaced event. We have convention for naming the project. You should have project name that contain service name as prefix. Ex: If your service name is Geekseat.OrderService than your message project should be Geekseat.OrderService.Messages.

orderservice_messages

You also should have create two directory for events and commands like this one. This will give you the namespace for events ( Geekseat.OrderService.Messages.Events ) and for commands ( Geekseat.OrderService.Messages.Commands)

Create PlaceOrder command on Commands folder and OrderPlaced events on Events folder. And Delete Class1.cs.

Make the content of PlaceOrder.cs like this.

placeorder

And the content of OrderPlaced.cs like this.

orderplaced

Please make sure that your namespace follow the conventions we mention above.

Create another endpoint for Geekseat.OrderClient.

ordercilent

Add GeekseatBus reference to Geekseat.OrderClient. Also add GeekseatBus.OrderService.Messages to OrderClient and OrderService.

addrefmessages

Now we can start creating a message handler for PlaceOrder in OrderService.

placeorderhandler

On Program.cs ( in OrderService ) you should start the bus with this code. Really simple startup right ?

programorderservice

You can try to run the OrderService to see what convention is used on creating queue and exchange in rabbitmq. Basically each service will have it’s own queue ( single queue for handling multiple message). This queue can be bind to event that the service interested in.

A service can also create an exchange for the event it’s published. You can check that OrderService have a queue named Geekseat.OrderService and Exchange Geekseat.OrderService.Messages.Events.OrderPlaced.

queue

exchange

Let’s now send some message to our service. Now we will concentrate on Geekseat.OrderClient.

orderclient_program

Run both OrderService and OrderClient. And press enter to send the message from Client.

runnning

Voila, it receive the message !

Publish and Subscribe Demo

Now we will publish an OrderPlaced event from OrderService. The publishing will be handle in PlaceOrderHandler. We will inject IGsBus into this handler and do publishing.

orderplacedhandler

Ok. Now let’s create subscriber for that event. We will leverage exchange in RabbitMQ. But of course this will be transparent from the user.

Create a new console project Geekseat.BillingService. Add reference to messages and GeekseatBus. Create message handler OrderPlacedHandler.

billservicehandler

Add the service startup for BillingService and we’re done.

billingstartup

Run all the console application (OrderService, BillingService and OrderClient). Enter the message from OrderClient and you can see that the event has been published to BillingService.

console_final.png

It Works !

We have open source this library on Github. You can download, experiment and give a pull request !

Happy Microservicing 🙂

 

Cheers

 

 

 

Advertisement

Porting Apache Avro into .NET Core

September 7, 2016 Leave a comment

We are from Geekseat has been used Avro extensively. Currently our project needs to be done on .NET core so .As i post previously i’m working on porting Apache Avro into .NET Core. Basically there are two Avro library available. One from Apache and one from Microsoft. I want to port both of library as that has been used a lot in big data application.

Let’s get back to Apache Avro.

There are two main problem that made headache when porting this one. One is AppDomain and IL Generator / Dynamic method is missing.

appdomainmissing

dynamicmethod

Both problem exists in the ObjectCreator.cs. This class is responsible for dynamically creating object on the fly based on the avro type.

ILGenerator has been known as the fastest object creator by Ayende Research. So i think this can be replaced with Expression tree but not sure how. Then i remember that Zeddy Iskandar has been create a forum post on how to create object with expression tree with constructor. You can see the method from this forum post. Here’s the complete source code of the ctor delegate.

One down, one more to go.

AppDomain has also been solved by Michael Whelan. Here’s the blog post around how to replace AppDomain.

I use the polyfill approach from that blog post. You can see that in action here.

After fixing both problem i’ve got 382 test passed and 6 failing. I’m quite happy with this result, declare victory and push that to repository. Thanks Zeddy and Michael.

test_passed

Cheers

 

 

Categories: .NET, net core Tags: , , , ,

Zookeeper C# Client with IKVM .NET

September 27, 2014 3 comments

Why ?

A lot of big data technology created with JVM. The language are vary from plain old Java, Scala and Clojure. There are a huge number of Apache project for this kind of stuff. The infrastructure for building a serious data product is amazingly mature in Java world.

The server is in Java . Ok. fine. But do we have to code in Java too ? At least as a client using the server ?. I know that JVM is awesome, but the language is not so well compare to C#. Especially the latest one C# 5. But for now we have to admit that .NET world is very lack of Server solution.

I always try to find a client library in C#/.NET but seems that it’s not really mature or has been already dead before birth. I will give you an example for this one.

 

Zookeeper is for the distributed zoo

Zookeeper has been used as a distributed process control. If you still remember the operating system 101 about process, threads, inter-process communication so this one should be easy for you to learn. If you familiar using lock or any synchronization mechanism like mutex, semaphore etc, just think this as way to do to coordinate multiple server synchronization. And it’s only expose a simple primitive like a file system. This is amazing and flexible. At the same time also make you do a lot of works to get the stuff working.

image

So we know that Zookeeper is good, it used by a lot of big data technology like Storm, Kafka, etc. So we need to find a client library to use it right ? Good luck finding it for .NET. There are a couple of library for doing that stuff but it’s either old or not up to date.

A couple of sample of that kind of library is :

https://www.nuget.org/packages/ZooKeeper.Net/

https://www.nuget.org/packages/ZooKeeperNet/

https://github.com/devhong/Zookeeper.Net

Read more…

Awesome free Cloud Services to try !!

December 7, 2012 Leave a comment

Not because I don’t like azure. but everyone is looking for something free. not to mention that I don’t have a credit card. Open-mouthed smile So I like a free cloud services. Especially with .NET support

I think both of this services need to be explored.

Appharbor is very simple to get started with and the feature I like is background process. You can combine the solution and be creative. For some services it’s free.

image

 

Realtime apps development is getting common latetly. Being able to push realtime data to client and streaming it efficiently and securely is the need of the modern apps. But building a distributed and networked apps is not easy. You need to know a lot about that. So why build one, let’s use the best in this area. I’ve just found this services and need to give it a try for the capability.

image

 

Do you have another alternatif ? Free and .NET support please ?

 

Cheers

Websocket and Windows .. Why…. :(

December 7, 2012 1 comment

As you know, I’ve been playing a lot with WebSocket lately. What I expect is the built in websocket support in IIS. Previously I use websocket library server like SuperWebsocket or

Fleck. But because we have already run IIS on port 80, we have to use another port for websocket. Not a standard one. This is actually against the specification and cause a lot of problem in the strict network policy environment.

image

The beauty of websocket is in that part. It use a standard port. Open a non standard port in some company is very difficult job. Firewall and proxy friendly in the future. Of course you can use tweak to make it run in the same port or use proxy to enable the behaviour. But that’s unnatural.

Finally i ‘m so happy because it will be supported in the IIS 8 with help .NET 4.5. You can take a look at this interesting article. Very simple codes for websocket. Just create the ashx handler and it works.

image

But the happiness ends there.. Take a look at this picture..

image

 

image

 

You should definitely sad to hear about this one. We can be expected just to change our production server in the short run. There are a lot of work need to be done.

So we have to find another alternative right ? until next post. Smile

 

Cheers

Categories: .NET, HTML 5, IIS, WebSocket Tags: , , ,