Purpose:
- Learn concurrency Go style for Java developers:
- Helping Java developers get trained in the Go programming language from a point of view of Java concurrency.
- Help Java developers migrate from Java's Thread/Future based concurrency to Go's Goroutine/Channel based concurrency.
- Reproduce common concurrency patterns used in Java through Go's model of concurrency.
Layout of samples (source code contains documentation to introduce ideas/concepts)
- ch1 - Demonstrates forking and joining of goroutines. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch1/forkjoin/main.go)
- ch2 - Futures demo (while there are no futures in Go, helps to bridge from Java to Go)
- future - Simple channel demo to communicate data across 2 goroutines. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch2/future/main.go)
- future2 - A "streaming" channel. This is when a channel communicates more than one value.(https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch2/future2/main.go)
- future3 - A pipeline - chaining of channels. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch2/future3/main.go)
- ch3 - Demonstrates generator/streaming pattern.
- basic - A simple generator. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch3/generator/basic/main.go)
- advanced1 - The consumer chooses when to stop the generator with a "done" channel. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch3/generator/advanced1/main.go)
- advanced2 - The producer chooses when to stop the generator based on some condition. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch3/generator/advanced2/main.go)
- ch4 - fanin - Demonstrates the fanin pattern - multiple tasks are generated by multiple sources and "fannedin" to one goroutine for processing.
- basic - A single task generator produces multiple tasks. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch4/fanin/basic/main.go)
- advanced - Multiple task generators produde multiple tasks. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch4/fanin/advanced/main.go)
- ch5 - fanout - Demonstrates the fanout process - Tasks are generated by a single goroutine and "fanned" out to multiple goroutines. Also demonstrates uses of sync.Mutex and sync.Waitgroup. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch5/fanout/main.go)
- ch6 - servicebus - Demonstrates the fanin and fanout process - Tasks are generated by a single goroutine and "fannedin" to one goroutine. This goroutine in turns "fans" out to multiple goroutines. One use of this is as a serivce bus. Also demonstrates uses of sync.Mutex and sync.Waitgroup. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch6/servicebus/main.go)
- ch7 - Reproduction of the CompletableFuture pattern.
- compose - A simple generator. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch7/compose/main.go)
- advancedcompose - The consumer chooses when to stop the generator with a "done" channel. Handles errors as well as cancellation. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch7/advancedcompose/main.go)
- ch8 - first response - Demonstrates returning first response from a set of requests. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch8/main.go)
- ch9 - fanin - Demonstrates throttling - ensuring that a serivce is not over-burdened with requests.
- basic - Basic throttling without timeout. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch9/throttle/basic/main.go)
- advanced - Throttling with timeout. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch9/throttle/advanced/main.go)
- Circuit breaker - Reproduce the functionality provided by Netflix circuit breaker. (https://github.com/Netflix/Hystrix/wiki/How-it-Works) Flowchart: (https://raw.githubusercontent.com/wiki/Netflix/Hystrix/images/hystrix-command-flow-chart.png)
Requirements of the circuit breaker:
- Fast fail - Client never blocks - either executes request or returns error with explanation.
- Auto repair - Circuit will repair itself after it is shutdown due to excess load.
- Default behavior - Breaker will execute default behavior in service failure scenarios. This is followed by call to cancel behavior.
- Cancel behavior - Breaker will execute cancel behavior in case of service failure. Cancel will be called after default.
- Timeout - Clients can configure timeouts, after which breaker will execute default and cancel behavior in order. Source code : (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch10/breaker/v1/breaker.go) Test code - contains examples that can be copied and pasted for working with the circuit. (https://github.com/rvauradkar1/goutil/blob/master/concurrent/ch10/breaker/v1/breaker_test.go)
Purpose:
- Demonstrate simple and advanced uses of the http standard library.
- Demonstrate setup of TLS and mutual TLS
- Demonstrate timeouts for client and server.
- Demonstrate building proxy servers.
- Demonstrate client side tracing of requests.