AmqGate solves RabbitMQ performance bottlenecks in high-load systems by eliminating connection overhead. This lightweight gateway accepts messages through Unix sockets and forwards them to RabbitMQ using a persistent connection pool.
In architectures like Nginx + PHP-FPM, each request typically creates:
-
New TCP connection to RabbitMQ
-
AMQP authentication handshake
-
Channel creation
-
Queue declaration
This results in:
-
High latency (50-100ms per message)
-
RabbitMQ overload from ephemeral connections
-
Blocked PHP processes during connection setup
-
Increased CPU/memory consumption
AmqGate acts as a high-performance proxy between your application and RabbitMQ:
[Your Application] → [Unix Socket] → [AmqGate] → [Persistent Connections] → [RabbitMQ]
-
10-100x faster message delivery (1-5ms vs 50-100ms)
-
Fixed connection pool to RabbitMQ instead of thousands of short-lived connections
-
Non-blocking asynchronous architecture in Go
-
Automatic reconnection to RabbitMQ
-
Simple integration via Unix sockets
-
🚀 Configurable AMQP connection pooling
-
🔌 Automatic RabbitMQ reconnection with exponential backoff
-
📈 Round-robin channel balancing
-
📝 Full RabbitMQ queue parameter support (durable, exclusive, etc.)
-
📊 JSON logging with detailed diagnostics
-
🔒 Safe message handling with context timeouts
https://hub.docker.com/r/pipetky/amqgate
docker run -it --rm -v /tmp/amqgate/:/tmp/amqgate/ -v $(pwd)/config.yaml:/app/config.yaml pipetky/amqgate:0.0.1
Go 1.18+
RabbitMQ server
git clone https://github.com/yourusername/amqgate.git
cd amqgate
CGO_ENABLED=0 GOOS=linux go build -o ./amqgate && \
sudo mv amqgate /usr/local/bin/
amqgate -c config.yaml
Example config.yaml file:
- qname: "example_q"
server: "192.168.10.3"
port: "5672"
cpq: 4 # Connections per queue
login: "test"
pass: "test"
vhost: "test" # Optional, default ""
durable: True # Optional, default False
no_wait: True # Optional, default False
auto_delete: True # Optional, default False
exclusive: True # Optional, default False
exchange: "test" # Optional, default False
- qname: "example_q2"
server: "192.168.10.3"
port: "5672"
cpq: 2 # Connections per queue
login: "test"
pass: "test"
./amqgate -c config.yaml
<?php
$myfile = fopen("test_50k.txt", "r") or die("Unable to open file!");
$file = fread($myfile,filesize("test_50k.txt"));
fclose($myfile);
$socket_file = "/tmp/amqgate/example_q.sock";
for ($i = 0; $i <= 100000; $i++) {
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
socket_connect($socket, $socket_file);
socket_write($socket, $file, $msg_len = strlen($file));
socket_close($socket);
}
?>
Test results (AMD EPYC 7B12, 64GB RAM, RabbitMQ 3.10):
Metric | Without AmqGate | With AmqGate |
---|---|---|
Send latency (p99) | 58 ms | 1.2 ms |
Max throughput | 1,200 msg/s | 24,000 msg/s |
RabbitMQ connections | 850 | 5 |
PHP CPU usage | 75% | 12% |
{
"level": "info",
"msg": "Connected to rabbitmq.local:5672",
"time": "2023-10-15T12:34:56Z"
}
{
"level": "warning",
"event": "reconnect",
"attempt": 3,
"queue": "web_events",
"time": "2023-10-15T12:35:01Z"
}
-
amqgate_messages_received_total (count)
-
amqgate_connection_errors_total (count)
-
amqgate_reconnect_attempts_total (count)
-
RabbitMQ queue depth
kill -SIGTERM $(pgrep amqgate)
-
Eliminates AMQP connection overhead - Maintains persistent connections to RabbitMQ
-
Reduces application complexity - No need for connection pooling in application code
-
Improves resource utilization - 1 AmqGate instance can serve multiple applications
-
Prevents RabbitMQ overload - Limits connection storms during traffic spikes
-
Simplifies scaling - Add more AmqGate instances as needed
Aleksandr Karabchevskiy - pipetky@gmail.com
Project Link: https://github.com/pipetky/AmqGate