Code Monkey home page Code Monkey logo

consumer-microservice-m2's Introduction

Microservice M2

The second micro-service (M2) was implemented using Go and some nice libs such as: (i) cobra to create a command line interface, (ii) Viper to read .env files, (iii) GIN to provide a web-service, and (iv) Gocron to trigger a task periodically.

M2 consumes the EMAIL queue as a message is ready. Then, the message is unmarshalled and a welcome email is sent to the added user. Then, information weather the email was correctly send or not is persisted into the database. Using Gocron a task periodically check if there is any email that wasn’t sent - if so, we try to send the email again.

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact
  7. Acknowledgements

About The Project

alt text Nowadays there are a lot of micro-services out there. One way to accomplish the communication between them is by using message-broker, such as RabbitMQ Kafka.

I have created two isolate micro-services as can be seen in the figure. The first micro-service (M2) was devised using Java Spring Boot.

M1 is just responsible to validade and persist a user into the database. Then, a message is sent to the RabbitMQ (message-broker). All messages are put into a queue (FIFO).

The second micro-service (M2) was implemented using Go and some nice libs such as: (i) cobra to create a command line interface, (ii) Viper to read .env files, (iii) GIN to provide a web-service, and (iv) Gocron to trigger a task periodically.

M2 consumes the EMAIL queue as a message is ready. Then, the message is unmarshalled and a welcome email is sent to the added user. Then, information weather the email was correctly send or not is persisted into the database. Using Gocron a task periodically check if there is any email that wasn’t sent - if so, we try to send the email again.

#golang #Java #SpringBoot #go #docker #rabbitmq

Important links:

M1 GitHub: link

M2 GitHub: link

Built With

Getting Started

Firstly install Go and Docker in your machine then install the following:

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • docker compose
    docker-compose up 

Installation

  1. Clone the repo
    git clone https://github.com/rdurelli/save-user-microservice-m1.git
  2. Install go mod
go get -u github.com/spf13/cobra
go get -u github.com/gin-gonic/gin
go get github.com/spf13/viper
go get -u github.com/go-sql-driver/mysql
go get -u github.com/jasonlvhit/gocron

Usage

Install all dependencies listed before

go run main.go

alt text

As can be seen we have available four commands: (i) completion, (ii) help, (iii) queue, and (iv) server. The first one is generated automatically by COBRA CLI. Command help show how to use the app. Command queue and server are the important ones. If I run:

  go run main.go queue --help

alt text

As can be noted we can specify some flags like address to connect the AMQP (RabbitMQ), SMTP Port etc. If none information is provided we have default values.

  go run main.go queue 

Calling the command queue will start the RabbitMQ alt text

The next command is the server command. By running you can define the port to create the web-service, default is 8080

  go run main.go server --help 

alt text

To create the web-service just call the following command:

  go run main.go server 

alt text

Two end-point is created as depicted in figure: (i) GET /api/emails and (ii) GET /api/emails/showAll

The first end-point show all emails that have been failed to be sent. The second end-point list all emails.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Rafael S. Durelli - @rafaeldurelli - [email protected]

Project Link: https://github.com/rdurelli/save-user-microservice-m1.git

consumer-microservice-m2's People

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.