Skip to content

Commit a3172b8

Browse files
authored
feat(elasticmq): init (#640)
https://github.com/softwaremill/elasticmq Adding ElasticMQ, an AWS SQS compatible, in-memory message queue system. Rest SQS must be enabled to run health check.
1 parent f386635 commit a3172b8

6 files changed

Lines changed: 174 additions & 0 deletions

File tree

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
@@ -9,6 +9,7 @@ short-title: Services
99
- [[cassandra]]#
1010
- [[clickhouse]]#
1111
- [[dynamodb-local]]#
12+
- [[elasticmq]]#
1213
- [[elasticsearch]]#
1314
- [[grafana]]#
1415
- [[tempo]]

nix/services/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ in
77
./azurite.nix
88
./clickhouse
99
./dynamodb-local.nix
10+
./elasticmq.nix
1011
./elasticsearch.nix
1112
./mongodb.nix
1213
./mysql

nix/services/elasticmq.nix

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

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 = "elasticmq-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
@@ -45,6 +45,7 @@
4545
"${inputs.services-flake}/nix/services/cassandra_test.nix"
4646
"${inputs.services-flake}/nix/services/clickhouse/clickhouse_test.nix"
4747
"${inputs.services-flake}/nix/services/dynamodb-local_test.nix"
48+
"${inputs.services-flake}/nix/services/elasticmq_test.nix"
4849
"${inputs.services-flake}/nix/services/grafana_test.nix"
4950
"${inputs.services-flake}/nix/services/memcached_test.nix"
5051
"${inputs.services-flake}/nix/services/minio_test.nix"

0 commit comments

Comments
 (0)