Search code examples
javaspring-bootamqpsocksqpid

How to create connection to AMQP queue over SSL using SOCKS proxy or any other proxy in java


Using using SOCKS proxy or any other Proxy, is there any way to connect to amqp queue over SSL using org.apache.qpid.jms.JmsConnectionFactory for environments where direct internet access is not available or amqps connection port is blocked by firewall.

I have tried connecting to amqp queue over SSL using org.apache.qpid.jms.JmsConnectionFactory on environments where internet is available.It is working fine!!!


Solution

  • Using the latest release of the Qpid JMS client (0.47.0 as of this answer) you can create your own Netty ProxyHandler instance that controls how the client connects through a proxy and configure it on the Connection Extensions as documented in the code here: the Factory exposes this via the setter for connection extensions. The test case for this feature shows some usages.

    Supplier<ProxyHandler> proxyHandlerSupplier = () -> {
        return new Socks5ProxyHandler(new InetSocketAddress("localhost", getPort()));
    };
    
    JmsConnectionFactory factory = new JmsConnectionFactory(remoteURI);
        factory.setExtension(JmsConnectionExtensions.PROXY_HANDLER_SUPPLIER.toString(), (connection, remote) -> {
            return proxyHandlerSupplier;
        });