create account

Building a Chat app with Docker and gRPC by tensor

View this thread on: hive.blogpeakd.comecency.com
· @tensor ·
$35.58
Building a Chat app with Docker and gRPC
![golang.jpg](https://cdn.steemitimages.com/DQmS4CeV2aFVAxKpxBQ8Jkwt7CP2YsKuaVVGetJca76MwS5/golang.jpg)

#### Repository
https://github.com/golang/go

#### What Will I Learn?

- You will learn how to add a Streaming Service to a gRPC
- You will learn how to put a Go Service in a Docker Container
- You will learn how to model a Chat application
- You will learn about WaitGroups and Go Routines
- You will learn how to block returns with channels

### Requirements
#### System Requirements:
##### Operating System:

- FreeBSD 10.3 or later
- Linux 2.6.23 or later with glibc
- macOS 10.10 or later
- Windows 7, Server 2008R2 or later
### Required Knowledge

- An understanding of APIs
- A basic understanding of Go
- Some understanding of micro service architecture. 

### Resources for Go and this Project:

- Awesome Go Github: https://github.com/avelino/awesome-go
- Golang Installation Page: https://golang.org/dl/
- Golang Home Page: https://golang.org/
- Golang Documentation Page: https://golang.org/doc/
- gRPC Website: https://grpc.io/
- Protocol Buffers Website: https://developers.google.com/protocol-buffers/
- Docker Website: https://www.docker.com/ 

#### Credits/Sources:
- Go Logo: https://golang.org/
### Difficulty

- Advanced


#### Description

In this Go video tutorial, we take a look at a more advanced gRPC example in the form of a simple Console Chat application.  This gRPC Chat Application makes use of a stream to push messages from the server to the clients.  We also take the server and put it into a Docker Container to make it easy for deployment and for containerization.  The application makes use of many goroutines and a `WaitGroup` to synchronize these goroutines.     


#### Streaming from the Server to the Client with gRPC

Like any RPC system, gRPC is primarily focused around allowing methods to be called remotely. To facilitate this functionality, there are four primary types of RPCs that can be specified with gRPC. In the prior tutorial, we took a look at unary RPC services exclusively.  These are the most basic forms of RPC services that can be defined with gRPC.  In this tutorial however, we add on a server streaming RPC service in conjunction with a unary RPC service.  

![broad-service.png](https://cdn.steemitimages.com/DQmY4EGiwkhrrp7LgkcZibmmmEw7JyTx572pEovCGCAyTvK/broad-service.png)

In this image, are the two main services for our Chat Application.  The `CreateStream` service is the server streaming service, denoted by the `stream` keyword in the returns statement. When a client connects to the server, the server will open a stream to the client. This will then allow the server to stream any received messages to the client and any other active clients which are also connected.  


#### Using Docker Containers for Go and gRPC Microservices

Docker is a revolutionary tool, that was also build with Go, that makes it easier to create, deploy and run applications inside of containers.  A container is a small environment detached from the major Operating System which contains all of the tools needed to build and execute the enclosed application. In this way, docker is a bit like a virtual machine; however, unlike a virtual machine, docker doesn't create an entire virtual operating system.  

![docker-container.png](https://cdn.steemitimages.com/DQmSynaffArNjHBLbfC6fHoE5qeyeFfZgLPApa6a3h93uSW/docker-container.png)   
 
For the example application, we make use of Docker to serve the server module of the Chat Application.  Using Docker in this manner, allows us to not only create a container to compile the server but also a separate container to run the application.  In the image above, we derive the container from an Alphine Linux kernel that contains the golang toolchain.  We also install a bunch of tools that are necessary for compiling the application using the `apk` package manager.  Afterwards, the folder structure of the original project is rebuilt inside of the container to make it easier to execute the application.    


The Source Code for this video may be found here: https://github.com/tensor-programming/docker_grpc_chat_tutorial


### Video Tutorial

<iframe width="560" height="315" src="https://www.youtube.com/embed/mML6GiOAM1w" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

### Curriculum 

- [Building a Basic RPC Server and Client with Go](https://steemit.com/utopian-io/@tensor/building-a-basic-rpc-server-and-client-with-go)
- [Building an Basic API with gRPC and Protobuf in Go](https://steemit.com/utopian-io/@tensor/building-an-basic-api-with-grpc-and-protobuf-in-go)
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 301 others
properties (23)
authortensor
permlinkbuilding-a-chat-app-with-docker-and-grpc
categoryutopian-io
json_metadata{"tags":["utopian-io","video-tutorials","steemstem","programming","technology"],"app":"steem-plus-app"}
created2019-02-14 21:29:33
last_update2019-02-14 21:29:33
depth0
children10
last_payout2019-02-21 21:29:33
cashout_time1969-12-31 23:59:59
total_payout_value26.768 HBD
curator_payout_value8.814 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,659
author_reputation87,856,203,149,624
root_title"Building a Chat app with Docker and gRPC"
beneficiaries
0.
accountsteemplus-pay
weight100
1.
accountutopian.pay
weight500
max_accepted_payout100,000.000 HBD
percent_hbd10,000
post_id79,876,902
net_rshares72,698,749,387,281
author_curate_reward""
vote details (365)
@pangoli ·
Pretty cool stuff. I really don't know where to start...
I just want to be able to contribute codes to steem :-(
πŸ‘  
properties (23)
authorpangoli
permlinkre-tensor-building-a-chat-app-with-docker-and-grpc-20190216t123038402z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-02-16 12:30:39
last_update2019-02-16 12:30:39
depth1
children1
last_payout2019-02-23 12:30:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length112
author_reputation66,834,329,736,250
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,948,789
net_rshares35,466,304,481
author_curate_reward""
vote details (1)
@tensor ·
If you want to start learning something like Go, I have a set of tutorials aimed at beginners.  I also have some other languages that I cover, Rust, Dart, Elixir, Elm, Kotlin etc which might help get you there depending on what you want to do.
properties (22)
authortensor
permlinkre-pangoli-re-tensor-building-a-chat-app-with-docker-and-grpc-20190216t214842537z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-02-16 21:48:39
last_update2019-02-16 21:48:39
depth2
children0
last_payout2019-02-23 21:48:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length243
author_reputation87,856,203,149,624
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,974,076
net_rshares0
@rosatravels ·
$8.96
Hi @tensor


Another fantastic video tutorial on this series.

Building a Chat app is very interesting and your teaching makes it easy for people to follow along.

The supplementary resources in Github created for this tutorial is fantastic. Thanks for all the hard work.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/9/1-2-1-1-1-1-1-1-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , ,
properties (23)
authorrosatravels
permlinkre-tensor-building-a-chat-app-with-docker-and-grpc-20190215t090232850z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["tensor"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/9/1-2-1-1-1-1-1-1-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-02-15 09:02:33
last_update2019-02-15 09:02:33
depth1
children2
last_payout2019-02-22 09:02:33
cashout_time1969-12-31 23:59:59
total_payout_value6.808 HBD
curator_payout_value2.152 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length725
author_reputation422,827,447,688,168
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,895,364
net_rshares17,297,915,782,605
author_curate_reward""
vote details (11)
@tensor ·
Thank you @rosatravels.  As always its nice to hear your feedback.
properties (22)
authortensor
permlinkre-rosatravels-re-tensor-building-a-chat-app-with-docker-and-grpc-20190215t231551144z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["rosatravels"],"app":"steemit/0.1"}
created2019-02-15 23:15:48
last_update2019-02-15 23:15:48
depth2
children0
last_payout2019-02-22 23:15:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length66
author_reputation87,856,203,149,624
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,925,918
net_rshares0
@utopian-io ·
Thank you for your review, @rosatravels! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-tensor-building-a-chat-app-with-docker-and-grpc-20190215t090232850z-20190218t043046z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-18 04:30:48
last_update2019-02-18 04:30:48
depth2
children0
last_payout2019-02-25 04:30:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length63
author_reputation152,955,367,999,756
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,030,003
net_rshares0
@steem-plus ·
SteemPlus upvote
Hi, @tensor!

You just got a **6.02%** upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in [here](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
authorsteem-plus
permlinkbuilding-a-chat-app-with-docker-and-grpc---vote-steemplus
categoryutopian-io
json_metadata{}
created2019-02-15 00:28:03
last_update2019-02-15 00:28:03
depth1
children0
last_payout2019-02-22 00:28:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length433
author_reputation247,952,188,232,400
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,882,097
net_rshares0
@steem-ua ·
#### Hi @tensor!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-building-a-chat-app-with-docker-and-grpc-20190215t101632z
categoryutopian-io
json_metadata"{"app": "beem/0.20.18"}"
created2019-02-15 10:16:33
last_update2019-02-15 10:16:33
depth1
children0
last_payout2019-02-22 10:16:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length285
author_reputation23,214,230,978,060
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,897,427
net_rshares0
@steemitboard ·
Congratulations @tensor! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td>https://steemitimages.com/60x70/http://steemitboard.com/@tensor/commented.png?201902151120</td><td>You got more than 300 replies. Your next target is to reach 400 replies.</td></tr>
</table>

<sub>_[Click here to view your Board](https://steemitboard.com/@tensor)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Do not miss the last post from @steemitboard:**
<table><tr><td><a href="https://steemit.com/valentine/@steemitboard/valentine-challenge-love-is-in-the-air"><img src="https://steemitimages.com/64x128/http://i.cubeupload.com/LvDzr5.png"></a></td><td><a href="https://steemit.com/valentine/@steemitboard/valentine-challenge-love-is-in-the-air">Valentine challenge - Love is in the air!</a></td></tr></table>

> Support [SteemitBoard's project](https://steemit.com/@steemitboard)! **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-tensor-20190215t124608000z
categoryutopian-io
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2019-02-15 12:46:06
last_update2019-02-15 12:46:06
depth1
children0
last_payout2019-02-22 12:46:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,150
author_reputation38,975,615,169,260
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,901,714
net_rshares0
@steemstem ·
$0.60
re-tensor-building-a-chat-app-with-docker-and-grpc-20190217t014205919z
<div class='text-justify'> <div class='pull-left'> <br /> <center> <img width='125' src='https://i.postimg.cc/9FwhnG3w/steemstem_curie.png'> </center>  <br/> </div> <br /> <br /> 

 This post has been voted on by the **SteemSTEM** curation team and voting trail in collaboration with **@curie**. <br /> 
 If you appreciate the work we are doing then consider [voting](https://www.steemit.com/~witnesses) both projects for witness by selecting [**stem.witness**](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=stem.witness) and [**curie**](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=curie)! <br /> 
For additional information please join us on the [**SteemSTEM discord**]( https://discord.gg/BPARaqn) and to get to know the rest of the community! </div>
πŸ‘  , , ,
properties (23)
authorsteemstem
permlinkre-tensor-building-a-chat-app-with-docker-and-grpc-20190217t014205919z
categoryutopian-io
json_metadata{"app":"bloguable-bot"}
created2019-02-17 01:42:09
last_update2019-02-17 01:42:09
depth1
children0
last_payout2019-02-24 01:42:09
cashout_time1969-12-31 23:59:59
total_payout_value0.450 HBD
curator_payout_value0.149 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length800
author_reputation262,017,435,115,313
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,980,427
net_rshares1,137,312,227,415
author_curate_reward""
vote details (4)
@utopian-io ·
Hey, @tensor!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-building-a-chat-app-with-docker-and-grpc-20190216t072904z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-02-16 07:29:06
last_update2019-02-16 07:29:06
depth1
children0
last_payout2019-02-23 07:29:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length588
author_reputation152,955,367,999,756
root_title"Building a Chat app with Docker and gRPC"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id79,940,804
net_rshares0