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.
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.
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.
Ok, Let’s get started. Here’s the schema of what we are going to achieve on this head first with GeekseatBus.
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.
Add reference to GeekseatBus nuget package to Geekseat.OrderService project.
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.
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.
And the content of OrderPlaced.cs like this.
Please make sure that your namespace follow the conventions we mention above.
Create another endpoint for Geekseat.OrderClient.
Add GeekseatBus reference to Geekseat.OrderClient. Also add GeekseatBus.OrderService.Messages to OrderClient and OrderService.
Now we can start creating a message handler for PlaceOrder in OrderService.
On Program.cs ( in OrderService ) you should start the bus with this code. Really simple startup right ?
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.
Let’s now send some message to our service. Now we will concentrate on Geekseat.OrderClient.
Run both OrderService and OrderClient. And press enter to send the message from Client.
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.
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.
Add the service startup for BillingService and we’re done.
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.
It Works !
We have open source this library on Github. You can download, experiment and give a pull request !
Happy Microservicing 🙂
You can follow the tutorial for publishing your library from this following series of youtube videos. You will need to request via Sonatype JIRA and wait for approval. It’s explained in the series.
However if you want the easiest way you can leverage using bitbucket pipeline. You can see the step by step on how to do that from this tutorial. It’s still in beta phase but looks promising. You should give it a try and ask for the trial. Yes, you need to request the trial first and wait for the approval.
The missing part on the tutorial above is on how to generate the key. Here’s how you can do that in Windows machine.
- Download the gnugpg for windows here
- Setup the key for signing
- Generate the key
- Find the list of the key to find the id
Let’s say that the id is 4C7CF393. We will use this key in the subsequent step.
- Publish the public key
gpg2 –keyserver hkp://pool.sks-keyservers.net –send-keys 4C7CF393
- Export the private key
gpg -a –export-secret-key 4C7CF393 > private-key.gpg
- Donlot http://gnuwin32.sourceforge.net/packages/openssl.htm for encryption
- Add the binaries to your PATH environment variables
- Encrypt the key
openssl aes-256-cbc -in private-key.gpg -out private-key.gpg.enc -pass pass:somesecretpwd
- Generate the key
- Upload that key to your repository. You can base your repository by copying this repository and replacing the private key there.
- Copy your source code and etc there.
- Replace the configuration for username and password by looking at README from this repository
- Edit the pom.xml so it publish your library
- You can follow the rest of the tutorial from this
Happy Publishing !
Finally ETP java library available in maven central. You could use this one in your pom.xml
<dependency> <groupId>org.energistics</groupId> <artifactId>etp</artifactId> <version>1.4.1</version> </dependency>
Here’s the sample of my pom.xml
It will automatically import avro as dependency. Now you can use it from your project.
You can also find the various way to add that to your build system from this link
All the source code and pom.xml that required to generate the java source using maven plugin can be seen from ETP Java Bitbucket
And you can find the pom example in my Github
.NET core supports three unit test framework in this version. We can also use Test Explorer in Visual Studio. Here’s the configuration in project.json
Here’s three project with each test framework and a couple of test class
Open the test explorer from Menu Test -> Window -> Test Explorer
Please build the test projects first and the test will be shown in Test Explorer.
You can access the source code and configuration in my Github
Happy TDD-ing !!
Geekseat is a agile soft company that locate in Bandung. My friends and mentee works there so i think why pay them a visit in their own base camp while i can. I got nothing to do besides of job hunting for jobless programmer.:)
I’m utterly shocked to the max
There are a couple unique things that you will find out in Geekseat. Its not something you can see in regular company in Indonesia.Well, I might be bias but I have a lots of friends and working on software industry for almost 8 years.
This culture still amaze me. How could they work like this? Is this even possible.
After visiting them I’m doing my research about the nature of geeks work and personality. It’s really different from other profession. I found a good book for this one. This book is really recommended for geek leaders or manager or whatever title is popular right now.
Here’s a unique culture in Geekseat.
- No dress code. You can wear anything to office.
- You can work anywhere remotely.
- The office is cleared at 4 pm.
- Family culture is really the key.
- No manager. Only a leader.
- No gap between junior and senior
- Agile is in its blood. Well it’s agile soft development in his name. What do you expect.
- Say no to overtime. Agile is all about sustainable pace.
- Interview process. Everyone is a family right from the beginning. Geekseat treat the candidate as customer. We never judge people. We educate right from beginning.
- Training process. We never leave the junior or newcomer going point blank without any direction. We provide training from the basic algorithm to advanced enterprise integration pattern.
- One person only focus on one project. We never overload the family member
I also read a book by Paul Sloane Leader’s guide to lateral thinking. The book mention that kind of organization called spaghetti. This model of organization produce a lot of productivity and creativity. Because geeks don’t respect the hierarchy structure. Power can’t control geeks !
Geeks can only be effective if leading by geeks. Because they respect technical knowledge. Behavior is irrelevant with productivity.
So previously I have been crafted this manifesto called Geeks Manifesto. Drum roll….
GEEKS HAVE NOTHING TO HIDE
GEEKS IS NOT OPPORTUNIST
GEEKS IS KIDDO THAT HACK THINGS
GEEKS LIKE TO SEE RESULT, FAST FEEDBACK AND COLLABORATION.
GEEKS IS ALL ABOUT SHOW ME THE CODE
IT’S ALL ABOUT REMOVING THE FRICTION.
So if you think you are geeks and doesn’t feel happy. You should asked yourself. Are you on the right home?
So I’m proudly announce that starting today I’m joining Geekseat as Technical Expert.
The only thing i need to prepare is short pants. So i’m not looking like an alien when using my usual office dress code.
Rock on !