Skip to content

Commit 1868c61

Browse files
committed
Allow picking ports for bazel run broker
This way multiple brokers can be run at the same time. Before that the only option was to use `bazel run start-cluster`, but it's not granular enough to run rabbits from different checkouts or with different configs.
1 parent 0dcbd6a commit 1868c61

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

BAZEL.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ Create a `user.bazelrc` by making a copy of `user-template.bazelrc` and updating
3333

3434
`bazel run broker`
3535

36+
You can set different environment variables to control some configuration aspects, like this:
37+
38+
```
39+
RABBITMQ_CONFIG_FILES=/path/to/conf.d \
40+
RABBITMQ_NODENAME=<node>@localhost \
41+
RABBITMQ_NODE_PORT=7000 \
42+
bazel run broker
43+
```
44+
45+
This will start RabbitMQ with configs being read from the provided directory. It also will start a node with a given node name, and with all listening ports calculated from the given one - this way you can start non-conflicting rabbits even from different checkouts on a single machine.
46+
47+
3648
### Running tests
3749

3850
Many rabbit tests spawn single or clustered rabbit nodes, and therefore it's best to run test suites sequentially on a single machine. Hence the `build --local_test_jobs=1` flag used in `.bazelrc`. Additionally, it may be reasonable to disable test sharding and stream test output when running tests locally with `--test_output=streamed` as an additional argument (to just disable sharding, but not stream output, use `--test_sharding_strategy=disabled`). Naturally that restriction does not hold if utilizing remote execution (as is the case for RabbitMQ's CI pipelines).

scripts/bazel/rabbitmq-run.sh

100644100755
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,63 @@ rmq_realpath() {
1717
}
1818

1919
write_config_file() {
20+
local rabbit_fragment=
21+
local rabbitmq_management_fragment=
22+
local rabbitmq_mqtt_fragment=
23+
local rabbitmq_web_mqtt_fragment=
24+
local rabbitmq_web_mqtt_examples_fragment=
25+
local rabbitmq_stomp_fragment=
26+
local rabbitmq_web_stomp_fragment=
27+
local rabbitmq_web_stomp_examples_fragment=
28+
local rabbitmq_stream_fragment=
29+
local rabbitmq_prometheus_fragment=
30+
31+
if [[ -n $RABBITMQ_NODE_PORT ]]; then
32+
rabbit_fragment="{tcp_listeners, [$RABBITMQ_NODE_PORT]}"
33+
rabbitmq_management_fragment="{listener, [{port, $(($RABBITMQ_NODE_PORT + 10000))}]}"
34+
rabbitmq_mqtt_fragment="{tcp_listeners, [$((1883 + $RABBITMQ_NODE_PORT - 5672))]}"
35+
rabbitmq_web_mqtt_fragment="{tcp_config, [{port, $((15675 + $RABBITMQ_NODE_PORT - 5672))}]}"
36+
rabbitmq_web_mqtt_examples_fragment="{listener, [{port, $((15670 + $RABBITMQ_NODE_PORT - 5672))}]}"
37+
rabbitmq_stomp_fragment="{tcp_listeners, [$((61613 + $RABBITMQ_NODE_PORT - 5672))]}"
38+
rabbitmq_web_stomp_fragment="{tcp_config, [{port, $((15674 + $RABBITMQ_NODE_PORT - 5672))}]}"
39+
rabbitmq_web_stomp_examples_fragment="{listener, [{port, $((15670 + $RABBITMQ_NODE_PORT - 5672))}]}"
40+
rabbitmq_stream_fragment="{tcp_listeners, [$((5552 + $RABBITMQ_NODE_PORT - 5672))]}"
41+
rabbitmq_prometheus_fragment="{tcp_config, [{port, $((15692 + $RABBITMQ_NODE_PORT - 5672))}]}"
42+
fi
2043
cat << EOF > "$RABBITMQ_CONFIG_FILE"
2144
%% vim:ft=erlang:
2245
2346
[
2447
{rabbit, [
48+
${rabbit_fragment}${rabbit_fragment+,}
2549
{loopback_users, []}
2650
]},
2751
{rabbitmq_management, [
52+
${rabbitmq_management_fragment}
2853
]},
2954
{rabbitmq_mqtt, [
55+
${rabbitmq_mqtt_fragment}
56+
]},
57+
{rabbitmq_web_mqtt, [
58+
${rabbitmq_web_mqtt_fragment}
59+
]},
60+
{rabbitmq_web_mqtt_examples, [
61+
${rabbitmq_web_mqtt_examples_fragment}
3062
]},
3163
{rabbitmq_stomp, [
64+
${rabbitmq_stomp_fragment}
65+
]},
66+
{rabbitmq_web_stomp, [
67+
${rabbitmq_web_stomp_fragment}
68+
]},
69+
{rabbitmq_web_stomp_examples, [
70+
${rabbitmq_web_stomp_examples_fragment}
71+
]},
72+
{rabbitmq_stream, [
73+
${rabbitmq_stream_fragment}
74+
]},
75+
{rabbitmq_prometheus, [
76+
${rabbitmq_prometheus_fragment}
3277
]},
3378
{ra, [
3479
{data_dir, "${RABBITMQ_QUORUM_DIR}"},

0 commit comments

Comments
 (0)