Skip to content

Commit 345f5e2

Browse files
committed
feat(elasticmq): init
1 parent 8b6244f commit 345f5e2

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed

doc/elasticmq.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ElasticMQ
2+
3+
[ElasticMQ](https://github.com/softwaremill/elasticmq) is a message queue system, offering an actor-based Scala and an SQS-compatible REST (query) interface.
4+
5+
## Usage example
6+
7+
<https://github.com/juspay/services-flake/blob/main/nix/services/elasticmq_test.nix>

doc/services.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ short-title: Services
88
- [[azurite]]#
99
- [[cassandra]]#
1010
- [[clickhouse]]#
11+
- [[elasticmq]]#
1112
- [[elasticsearch]]#
1213
- [[grafana]]#
1314
- [[tempo]]

nix/services/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ in
66
./apache-kafka.nix
77
./azurite.nix
88
./clickhouse
9+
./elasticmq.nix
910
./elasticsearch.nix
1011
./mongodb.nix
1112
./mysql

nix/services/elasticmq.nix

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{ config, pkgs, lib, name, ... }:
2+
3+
{
4+
options = {
5+
package = lib.mkPackageOption pkgs "elasticmq-server-bin" { };
6+
7+
nodeAddress = {
8+
protocol = lib.mkOption {
9+
type = lib.types.str;
10+
default = "http";
11+
};
12+
host = lib.mkOption {
13+
type = lib.types.str;
14+
default = "localhost";
15+
};
16+
port = lib.mkOption {
17+
type = lib.types.port;
18+
default = 9324;
19+
};
20+
contextPath = lib.mkOption {
21+
type = lib.types.str;
22+
default = "";
23+
};
24+
};
25+
26+
restSqs = lib.mkOption {
27+
type = lib.types.submodule {
28+
options = {
29+
enabled = lib.mkOption {
30+
type = lib.types.bool;
31+
default = true;
32+
};
33+
bindPort = lib.mkOption {
34+
type = lib.types.port;
35+
default = 9324;
36+
};
37+
bindHost = lib.mkOption {
38+
type = lib.types.str;
39+
default = "0.0.0.0";
40+
};
41+
};
42+
};
43+
default = { };
44+
};
45+
46+
restStats = lib.mkOption {
47+
type = lib.types.submodule {
48+
options = {
49+
enabled = lib.mkOption {
50+
type = lib.types.bool;
51+
default = true;
52+
};
53+
bindPort = lib.mkOption {
54+
type = lib.types.port;
55+
default = 9325;
56+
};
57+
bindHost = lib.mkOption {
58+
type = lib.types.str;
59+
default = "0.0.0.0";
60+
};
61+
};
62+
};
63+
default = { };
64+
};
65+
66+
generateNodeAddress = lib.mkOption {
67+
type = lib.types.bool;
68+
default = false;
69+
};
70+
71+
extraOptions = lib.mkOption {
72+
type = lib.types.lines;
73+
default = "";
74+
description = "Additional raw HOCON options to append.";
75+
};
76+
};
77+
78+
config.outputs.settings.processes."${name}" =
79+
let
80+
confFile = pkgs.writeText "elasticmq.conf" ''
81+
node-address {
82+
protocol = ${config.nodeAddress.protocol}
83+
host = ${config.nodeAddress.host}
84+
port = ${toString config.nodeAddress.port}
85+
context-path = "${config.nodeAddress.contextPath}"
86+
}
87+
88+
rest-sqs {
89+
enabled = ${lib.boolToString config.restSqs.enabled}
90+
bind-port = ${toString config.restSqs.bindPort}
91+
bind-hostname = "${config.restSqs.bindHost}"
92+
}
93+
94+
rest-stats {
95+
enabled = ${lib.boolToString config.restStats.enabled}
96+
bind-port = ${toString config.restStats.bindPort}
97+
bind-hostname = "${config.restStats.bindHost}"
98+
}
99+
100+
generate-node-address = ${lib.boolToString config.generateNodeAddress}
101+
102+
${config.extraOptions}
103+
'';
104+
105+
startCommand = pkgs.writeShellApplication {
106+
name = "start-elasticmq";
107+
runtimeInputs = [ config.package ];
108+
runtimeEnv = {
109+
JAVA_TOOL_OPTIONS = "-Dconfig.file=${confFile}";
110+
};
111+
text = ''
112+
exec elasticmq-server
113+
'';
114+
};
115+
in
116+
{
117+
command = startCommand;
118+
119+
readiness_probe = lib.optionalAttrs config.restSqs.enabled {
120+
http_get = {
121+
host = config.restSqs.bindHost;
122+
port = config.restSqs.bindPort;
123+
path = "/health";
124+
};
125+
initial_delay_seconds = 2;
126+
period_seconds = 10;
127+
timeout_seconds = 4;
128+
success_threshold = 1;
129+
failure_threshold = 5;
130+
};
131+
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
132+
availability = {
133+
restart = "on_failure";
134+
max_restarts = 5;
135+
};
136+
};
137+
}

nix/services/elasticmq_test.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{ pkgs
2+
, config
3+
, ...
4+
}: {
5+
services.elasticmq."elasticmq1" = {
6+
enable = true;
7+
};
8+
9+
settings.processes.test =
10+
let
11+
inherit (config.services.elasticmq."elasticmq1".restSqs) bindHost bindPort;
12+
in
13+
{
14+
command = pkgs.writeShellApplication {
15+
name = "dynamodb-test";
16+
runtimeInputs = with pkgs; [ awscli2 jq ];
17+
runtimeEnv = {
18+
AWS_ACCESS_KEY_ID = "fake";
19+
AWS_SECRET_ACCESS_KEY = "fake";
20+
AWS_DEFAULT_REGION = "us-east-1";
21+
};
22+
text = ''
23+
aws sqs list-queues --endpoint-url "http://${bindHost}:${toString bindPort}" \
24+
| jq '.QueueUrls'
25+
'';
26+
};
27+
depends_on."elasticmq1".condition = "process_healthy";
28+
};
29+
}

test/flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"${inputs.services-flake}/nix/services/azurite_test.nix"
4545
"${inputs.services-flake}/nix/services/cassandra_test.nix"
4646
"${inputs.services-flake}/nix/services/clickhouse/clickhouse_test.nix"
47+
"${inputs.services-flake}/nix/services/elasticmq_test.nix"
4748
"${inputs.services-flake}/nix/services/grafana_test.nix"
4849
"${inputs.services-flake}/nix/services/memcached_test.nix"
4950
"${inputs.services-flake}/nix/services/minio_test.nix"

0 commit comments

Comments
 (0)