AMQProxy is an open source AMQP proxy service that can reuse AMQP connections. AMQProxy enables a client, such as a PHP client, that normally can use only short-lived connections to use persistent connections. This reduces the consumption of network and Message Queue for RabbitMQ resources.

Prerequisites

OpenSSL is installed on the client-side server if you want to connect AMQProxy to Message Queue for RabbitMQ by using SSL. For more information, see Downloads.
Notice In VPC environments, you are not allowed to connect AMQProxy to Message Queue for RabbitMQ by using SSL.

Background information

Clients in some programming languages, such as PHP, do not support persistent connections. If you frequently open and close connections for the clients, a large number of network and Message Queue for RabbitMQ resources are consumed, which imposes great pressure on Message Queue for RabbitMQ.

dg_AMQP Proxy_1

AMQProxy

AMQProxy is an open source AMQP proxy service provided by CloudAMQP. AMQProxy allows you to open persistent connections between clients and Message Queue for RabbitMQ. After you deploy AMQProxy on the server of a client, requests from the client to Message Queue for RabbitMQ are first sent to AMQProxy and then forwarded to Message Queue for RabbitMQ.

AMQProxy processes connection-related requests initiated by a client based on the following logic:

  • If the client sends a request to open a connection, AMQProxy checks whether an existing connection can be reused based on the username, password, and vhost. If an existing connection meets the reuse requirements, the connection is reused. If no existing connections meet the reuse requirements, AMQProxy opens a new connection for the client and Message Queue for RabbitMQ.
  • If the client sends a request to close a connection, AMQProxy directly returns OK but does not close the connection with Message Queue for RabbitMQ. When the client requests to open the connection again, AMQProxy directly reuses this connection.
dg_AMQP Proxy_2

For more information about AMQProxy, see AMQProxy.

Deploy AMQProxy

  1. Run the following command to download the AMQProxy compressed package:
    wget https://github.com/cloudamqp/amqproxy/releases/download/v0.4.4/amqproxy-0.4.4-1.linux-x86_64-static.tar.gz
    Note AMQProxy 0.4.4 is used as an example in this topic. For more AMQProxy versions, see Releases.
  2. Run the following command to decompress the downloaded package:
    tar -xzvf amqproxy-0.4.4-1.linux-x86_64-static.tar.gz
  3. Run the following command to open the AMQProxy folder:
    cd amqproxy/
  4. Run the following command to start AMQProxy:
    ./amqproxy -l LISTEN_ADDRESS -p LISTEN_PORT AMQP_URL
    Parameter Description
    LISTEN_ADDRESS The IP address of AMQProxy. You can set this parameter to 127.0.0.1 because AMQProxy is deployed on the server of the client.
    LISTEN_PORT The listening port of AMQProxy. The client sends requests to AMQProxy over this port. All available ports such as port 5673 can be used as the listening port.
    AMQP_URL The URL of the Message Queue for RabbitMQ instance. The URL must be in the {amqp|amqps}://{endpoint} format.
    • amqp: indicates that AMQP is used. Use this parameter if SSL is not used.
    • amqps: indicates that the AMQP and SSL protocols are used. Use this parameter if SSL is used.
    • endpoint: indicates the endpoint of the Message Queue for RabbitMQ instance. You can view the endpoint on the Instances page of the Message Queue for RabbitMQ console. For more information, see View instance details.
    Sample command:
    ./amqproxy -l 127.0.0.1 -p 5673 amqps://188XXX420.mq-amqp.cn-hangzhou-a.aliyuncs.com
    Sample command output:
    Proxy upstream: 188XXX420.mq-amqp.cn-hangzhou-a.aliyuncs.com:5671 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 the Message Queue for RabbitMQ instance.
  5. Change the host IP address and port number in the code of the client to the IP address and listening port of AMQProxy.
    factory.setHost("127.0.0.1");
    factory.setPort(5673);