For a blocking, non-TLS AMQP connection, Spring’s RabbitConnectionFactoryBean can pass a SOCKS-aware socket factory to the RabbitMQ Java client.

If Commons Net is already available, configure the existing factory bean before initialization:

var socksProxy = new java.net.Proxy(
    java.net.Proxy.Type.SOCKS,
    new java.net.InetSocketAddress("proxy.example", 1080));
rabbitFactoryBean.setSocketFactory(
    new org.apache.commons.net.DefaultSocketFactory(socksProxy));

rabbitFactoryBean is the application’s RabbitConnectionFactoryBean. Keep its broker host, AMQP port, account and Spring connection-management setup. The broker remains the destination; the SocketFactory creates the sockets that reach it through SOCKS. For a non-sensitive test against a public broker where public intermediaries are permitted, the SOCKS proxy list offers candidates; match the runtime’s supported SOCKS version and confirm access to the actual broker host and port.

Commons Net’s factory creates an unconnected java.net.Socket using the supplied Proxy. RabbitMQ’s blocking connection code then connects that socket using its normal connection path. Merely exporting HTTP_PROXY does not supply this AMQP socket factory.

RabbitMQ documents that the SocketFactory hook applies to blocking I/O. A client configured for NIO or another transport needs that transport’s supported hook. For AMQPS, retain a suitable TLS socket factory and destination verification; replacing it with the plain factory above is not a complete TLS configuration.

متعلقہ مضامین