Debian Codegraph @

autopaho/examples/docker/readme.md

raw symbols SCIP
1 Docker example
2 ==============
3
4 This folder contains all that is needed to build an environment with a publisher, server (mosquitto) and subscriber
5 using docker (ideally `docker-compose`). While it provides an end-to-end example its primary purpose is to act as a
6 starting point for producing reproducible examples (when logging an issue with the library).
7
8 Because the publisher (`pub`), server (`mosquitto`) and subscriber (`sub`) run in separate containers this setup closely
9 simulates a real deployment. One thing to bear in mind is that the network between the containers is very fast and
10 reliable (but there are some techniques that can be used to simulate failures etc).
11
12 The subscriber connects via websockets whereas the publisher uses a TCP connection (this is set via environmental
13 variables).
14
15 Note: The docker-compose file sets the context to the root of paho.golang; this is done to avoid the need for
16 publisher and subscriber to be in their own modules. This avoids the need to import `paho.golang` (which would
17 make using this for testing changes to `autopaho` difficult because go would fetch the package from git).
18
19 # Usage
20
21 Ensure that you have [docker](https://docs.docker.com/get-docker/) and
22 [docker-compose](https://docs.docker.com/compose/install/) installed.
23
24 To start everything up change into the `cmd/docker` folder and run:
25
26 ```
27 docker-compose up --build --detach
28 ```
29
30 This will start everything up in the background. You can see what is happening by running:
31
32 ```
33 docker-compose logs --follow
34 ```
35
36 This will display a lot of information (mosquitto is running with debug level logging). To see the subscriber logs:
37
38 ```
39 docker-compose logs --follow sub
40 ```
41
42 Note: Messages received by the subscriber will be written to `binds/sub/` if `subdemo_writeToDisk` is set to `true` in
43 `docker-compose.yml` (you may want to delete the contents of this file from time to time!).
44
45 To stop everything run:
46
47 ```
48 docker-compose down
49 ```
50
51 Feel free to copy the folder and modify the publisher/subscriber to work as you want them to!
52
53 Note: The `pub` and `sub` containers connect to mosquitto via the internal network (`test-net`) but mosquitto should
54 also be available on the host port `8883` if you wish to connect to it. This will not work if you have mosquitto
55 installed locally (edit the `docker-compose.yml` and change the `published` port).
56
57 # Simulating Network Connection Loss
58
59 You can simulate the loss of network connectivity by disconnecting the network adapter within a container. e.g.
60
61 ```
62 docker network disconnect lostpackets_test-net docker-pub-1
63 docker network connect lostpackets_test-net docker-pub-1
64 ```
65