matthiasnoback / building-autonomous-services-workshop Goto Github PK
View Code? Open in Web Editor NEWCode and assignments for the "Building Autonomous Services" workshop module.
Home Page: https://training.matthiasnoback.nl
License: MIT License
Code and assignments for the "Building Autonomous Services" workshop module.
Home Page: https://training.matthiasnoback.nl
License: MIT License
If forgotten, it's very annoying.
See the fix-commit in myhammer branch. Also update the assignment: the response format of stock_web/stockLevels should be: { "productId": 10 }
Make it easier to do so, e.g. provide scenario, provide empty steps, and show links.
Nicely expanding/collapsing, etc.
In Git Bash, $(pwd) returns the current working directory in MINGW, which looks something like "/c/building-autonomous-services-workshop", however this isn't the path we want in the bin/install
script when composer install is executed.
$(pwd -W) would solve the issue.
E.g.:
# Check if the script is run in Git Bash and get working_dir accordingly.
if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
working_dir=$(pwd -W)
else
working_dir=$(pwd)
fi
# Pull Composer Docker image and run composer install
echo "Installing Composer dependencies"
docker pull composer:latest --quiet
docker run --rm --volume "$working_dir":/app:cached --user "$(id -u):$(id -g)" composer:latest \
install \
--ignore-platform-reqs \
--prefer-dist \
--no-progress
I think this is general trouble with Docker under Mac, when exposing ports in the docker-compose.yml
files like this:
ports:
- "80:80"
Docker can bind then to any interface or ipv6 and then 127.0.0.1:80 won't be accessible. To fix this, we can use exact host:port binding long format, supported by Docker.
ports:
- "127.0.0.1:80:80"
Instead of increased and decreased.
A colleague of mine ran into the problem, that he couldn't run docker without sudo
.
On linux, to run docker without super user privileges, the desired user needs to be a member of the docker group.
(Tutorial: https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)
I don't know if it is worth it to mention it in the README.
As there are already notes for windows users, there might be a place for linux users as well.
That being said, I'm happy if you want to close this without changes, as this is more of a "how to install docker" kind of thing.
bin/install
Pulling Docker images
Installing Composer dependencies
unknown flag: --quiet
See 'docker pull --help'.
It does seem to work none the less, but I guess that flag can be removed here.
Apparently some OSes don't have it defined as environment variable.
It's a lot of work in one go.
Thereby simplifying the Makefile
.
Dear Matthias,
Apologies for the late notice.
I'm having trouble getting the project to work. I am using Windows and have already encountered some hick ups, but I don't seem to find any information to fix the latetst one I ran into:
C:\Users\jonia\building-autonomous-services-workshop>make up
process_begin: CreateProcess(NULL, uname -s, ...) failed.
process_begin: CreateProcess(NULL, id -u, ...) failed.
process_begin: CreateProcess(NULL, id -g, ...) failed.
(grep "127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost" /etc/hosts) || echo '127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost' | sudo tee -a /etc/hosts
127.0.0.1 dashboard.localhost sales.localhost purchase.localhost catalog.localhost stock.localhost
mkdir -p /.composer/.composer] Fout 1
The syntax of the command is incorrect.
make: *** [
I have Docker desktop for windows and this contains the docker compose as instructed on the docker website. Do you have any tip how to solve this?
Thank you in advance.
Kind regards
Joni
Make it clear how the second snippet belongs to snippet 1.
Maybe add a toArray method? It's good to set an example for this, instead of the way we produce events ad hoc.
"Since making a reservation effectively decreases the balance, it shouldn't happen again upon delivering a sales order. The Stock consumer should no longer manually decrease the balance. It should only produce the "stock level decreased" event. And it should do so upon receiving a "stock reservation accepted" event (not upon receiving a "sales order delivered" event)." - see solution to assignment 5 in mytheresa_2019: we should dispatch the other event also in the makeReservationAction()
.
Events/commands/states related to if the sales order is ready to be delivered.
$ ./bin/stop
ERROR: No such service:
bin/stop
tries to offer a default value to stop all services. However, as the argument is enclosed in quotes, the shell will pass the empty string as an argument, as opposed to omitting the argument.
Omitting the quotes in combination with using $@
might be a solution to allow passing multiple service names.
As discussed during the training - the implementation of the Balance::processReceivedGoodsAndRetryRejectedReservations()
method is not correct:
So the final method implementation should be:
final class Balance implements IdentifiableObject {
public function processReceivedGoodsAndRetryRejectedReservations(int $quantity): ?Reservation
{
$expectedQuantity = $this->stockLevel + $quantity;
foreach ($this->rejectedReservations as $key => $rejectedReservation) {
if ($rejectedReservation->quantity() <= $expectedQuantity) {
unset($this->rejectedReservations[$key]);
$this->reservations[] = $rejectedReservation;
// Decrease stock by reservation minus extra quantity that should be added to stock
$this->decrease($rejectedReservation->quantity() - $quantity);
return $rejectedReservation;
}
}
$this->increase($quantity);
return null;
}
}
Or even simpler if we first - increase the quantity of balance and then decrease it by reservation quantity:
final class Balance implements IdentifiableObject {
public function processReceivedGoodsAndRetryRejectedReservations(int $quantity): ?Reservation
{
$this->increase($quantity);
foreach ($this->rejectedReservations as $key => $rejectedReservation) {
if ($rejectedReservation->quantity() <= $this->stockLevel) {
unset($this->rejectedReservations[$key]);
$this->reservations[] = $rejectedReservation;
$this->decrease($rejectedReservation->quantity());
return $rejectedReservation;
}
}
return null;
}
}
P.S.: Both method implementations work in my solution =)
Somehow it doesn't pull all the required images when using Docker version 20.x
It does work on Linux. So, maybe it's a Docker Desktop issue?
This will make for a nice exercise: automatically placing a purchase order.
Docker says: "Bind for 0.0.0.0:80 failed: port is already allocated
I also ran into that one, and it is not always trivial to find/close the service in question
I was wondering if we could just use the more simple installation steps as per https://github.com/matthiasnoback/layers-ports-and-adapters-workshop/#option-1-docker
Open http://localhost:8080
always works super esily and without conflicts of port 80.
After the install and start of the app - the links will not work as they are custom domains that require to set them in hosts of the OS.
So there should be a step that lists domains which should be added to the local OS hosts file:
127.0.0.1 dashboard.localtest.me
127.0.0.1 catalog.localtest.me
127.0.0.1 stock.localtest.me
127.0.0.1 sales.localtest.me
127.0.0.1 purchase.localtest.me
Also another suggestion would be to get rid of the domain names and instead expose the ports from docker containers to host OS to be able to use URLs like localhost:9001
, localhost:9002
, etc.
So the process manager doens't redo all the work...
After running bin/start
, I get the following error:
Creating network "building-autonomous-services-workshop_default" with the default driver
Creating network "building-autonomous-services-workshop_traefik" with the default driver
ERROR: Service 'catalog_php' needs to be built, but --no-build was passed.
When rerunning the command, it cycles through different services that need to be built.
Removing the --no-build
flag, or separately building the containers, resolves the issue.
I don't know why you pass the --no-build
flag. I assume this is for good reason. Therefore, I think the problem could be fixed in the documentation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.