Distributed Message Service RabbitMQ

Using AMQProxy to solve the problem of reusing client connections such as PHP

2024-06-27 07:06:07

AMQProxy is an open source AMQP proxy service with the ability to reuse AMQP Connection. You can use this proxy service to enable clients that would otherwise only use short-lived connections (e.g. PHP clients) to use long-lived connections, to reduce network resource consumption and DMS RabbitMQ resource consumption.

Before You Begin

If you want to use SSL to connect AMQProxy and DMS RabbitMQ, please make sure your client server has OpenSSL installed.

Background

Clients in some languages (e.g. PHP clients) cannot use long-lived connections, which frequently enable or disable the connections, consuming a large amount of network resources and DMS RabbitMQ resources, thus causing great pressure on DMS RabbitMQ.

AMQProxy

AMQProxy is an open-source AMQP proxy service provided by Cloud AMQP. The client can maintain a long-lived connection with the DMS RabbitMQ through this proxy service. When the client server deploys AMQProxy, the requests between the client and the DMS RabbitMQ will be sent to AMQProxy first, and then forwarded to each other by AMQProxy.

The logic of AMQProxy processing connection-related requests initiated by the client is as follows:

If the client sends a request to enable the connection, AMQProxy will check whether there is a suitable connection that can be reused based on the username, password, and Vhost. If so, the connection will be reused; if not, AMQProxy will replace the client and RabbitMQ to enable the connection.

If the client sends a request to disable the connection, AMQProxy will directly respond with OK, but will not disable the connection with the DMS RabbitMQ. When the client requests to enable the connection next time, AMQProxy will directly use it.

For more information about AMQProxy, see AMQProxy.

Deploying AMQProxy

(1) Download and install AMQProxy.

Open source project address: https://github.com/cloudamqp/amqproxy

There is an installation package in the releases directory, which can be decompressed locally after downloading

(2) Start AMQProxy.

./amqproxy -l LISTEN_ADDRESS -p LISTEN_PORT AMQP_URL

Parameter

Description

LISTEN_ADDRESS

AMQProxy   IP address. Since AMQProxy is deployed on the client server, you can use the   local address 127.0.0.1 directly.

LISTEN_PORT

AMQProxy   listening port. Client requests are sent to AMQProxy through this port. The   port can be any available port, such as 5673.

AMQP_URL

The URL   of DMS RabbitMQ instance. The format is {amqp|amqps}://{endpoint}.

l   amqp:   AMQP protocol. Used when not using SSL connection.

l   amqps:   AMQP/SSL protocol. Used when using SSL connection.

l   endpoint:   the access point of DMS RabbitMQ instance. You can view it on the instance   details page of DMS RabbitMQ console.

Example command is as follows:

./amqproxy -l 127.0.0.1 -p 5673 amqps://192.168.0.100:5672

Return example is as follows:

Proxy upstream: 192.168.0.100:5672 TLS

Proxy listening on 127.0.0.1:5673

0 clients                0 upstreams

Parameter

Description

clients

The number of connections between the client and AMQProxy.

upstreams

The number of connections between AMQProxy and DMS RabbitMQ   instance.

(3) Modify the Host and port in the client code to AMQProxy IP address and listening port.

factory.setHost("127.0.0.1");

factory.setPort(5673);


6e2zI81hHD5K