How to connect to remote RabbitMQ Server behind a corporation proxy, in Java Code

4,686 views
Skip to first unread message

Wang Guohua

unread,
Jul 17, 2015, 4:10:36 AM7/17/15
to rabbitm...@googlegroups.com
Dear all,

We are using proxy to connect to internet.

I can connect to URL by set proxy properties.
System.getProperties().setProperty("http.proxyHost", "proxy.houston.hp.com");
System.getProperties().setProperty("http.proxyPort", "8080");
URL url = new URL(urlString);
InputStream content = (InputStream) url.getContent();
And, my ssh connect to internet server with proxy is good.

But, my rabbitmq connection to internet RabbitMQ server failed with connection timeout:
System.getProperties().setProperty("http.proxyHost", "proxy.houston.hp.com");
System.getProperties().setProperty("http.proxyPort", "8080");

ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("xxxx");
factory.setPassword("xxxx");

connection = factory.newConnection();

Any help?

Thanks
Andy.

Michael Klishin

unread,
Jul 17, 2015, 9:06:26 AM7/17/15
to rabbitm...@googlegroups.com, Wang Guohua
 On 17 July 2015 at 11:10:39, Wang Guohua (sunny...@gmail.com) wrote:
> But, my rabbitmq connection to internet RabbitMQ server failed
> with connection timeout:
> System.getProperties().setProperty("http.proxyHost",
> "proxy.houston.hp.com");
> System.getProperties().setProperty("http.proxyPort",
> "8080");
>
> ConnectionFactory factory = new ConnectionFactory();
> factory.setHost("ec2-52-10-172-31.us-west-2.compute.amazonaws.com");
> factory.setUsername("xxxx");
> factory.setPassword("xxxx");
>
> connection = factory.newConnection();
>
> Any help?

RabbitMQ clients do not use HTTP. They use a different protocol which is TCP-based.
So you are looking for a TCP proxy (SOCKS, HTTP CONNECT-based, etc).

JDK has a documentation page about that:
http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Charles Conrad

unread,
Jul 4, 2016, 10:00:34 PM7/4/16
to rabbitmq-users, sunny...@gmail.com
I am having a similar problem that I have to get through a proxy to reach my rabbit server on the cloud. After creating the Proxy object, how do I use it for creating a connection via a ConnectionFactory?

When trying to reach a webpage, you can use a URL object with the proxy. As described in the docs you linked.

SocketAddress addr = new InetSocketAddress("socks.example.com", 1080);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
URL url = new URL("ftp://ftp.gnu.org/README");
URLConnection conn = url.openConnection(proxy);

How do I use this proxy with the rabbit api?

Thanks.

Michael Klishin

unread,
Jul 5, 2016, 8:35:02 AM7/5/16
to rabbitm...@googlegroups.com
RabbitMQ Java client doesn't provide any special support for SOCKS proxies. You should
be able to use any proxy that supports arbitrary TCP traffic.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashok Jothikrishnan

unread,
May 16, 2020, 9:03:49 AM5/16/20
to rabbitmq-users
Can someone please help? I tried setting socks proxy host and port, but rabbitmq doesn't take them at all.

System.getProperties().setProperty("sockProxyHost", "xx.xx.xx.xx" );
System.getProperties().setProperty("sockProxyPort", "3128" );
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitm...@googlegroups.com.

To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Klishin

unread,
May 16, 2020, 12:05:14 PM5/16/20
to rabbitmq-users
From earlier in this thread:
> RabbitMQ Java client doesn't provide any special support for SOCKS proxies. You should
> be able to use any proxy that supports arbitrary TCP traffic.
>
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/e4a3fe5e-bab0-4f2e-8f67-bf8ca3d51270%40googlegroups.com.

Ashok Jothikrishnan

unread,
May 16, 2020, 7:34:27 PM5/16/20
to rabbitmq-users
I tried all this. It doesn't connect to RabbitMQ. If I get the firewall opened, it works fine.

System.getProperties().setProperty( "java.net.useSystemProxies", "true" );
System.getProperties().setProperty("http.proxyHost", "XX.XX.XX.XX" );
System.getProperties().setProperty("http.proxyPort", "3128" );
System.getProperties().setProperty("proxyHost", "XX.XX.XX.XX" );
System.getProperties().setProperty("proxyPort", "3128" );
// System.getProperties().setProperty( "java.net.useSystemProxies", "true" );
System.getProperties().setProperty("sockProxyHost", "XX.XX.XX.XX" );
System.getProperties().setProperty("sockProxyPort", "3128" );



To unsubscribe from this group and stop receiving emails from it, send an email to rabbitm...@googlegroups.com.

Ashok Jothikrishnan

unread,
May 16, 2020, 7:35:16 PM5/16/20
to rabbitmq-users
I also tried to socket configurator and configured it. Still I could not.

public class SocketProxyConfigurator extends DefaultSocketConfigurator {
private static final Logger log = LoggerFactory.getLogger(SocketProxyConfigurator.class);
public SocketProxyConfigurator() {
SocketAddress sa = InetSocketAddress.createUnresolved("XX.XX.XX.XX", 3128);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, sa);
try {
Socket socket = new Socket(proxy);
super.configure(socket);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

Ashok Jothikrishnan

unread,
May 18, 2020, 8:17:03 PM5/18/20
to rabbitmq-users
All, it finally worked. There was no big magic. We setup proxyHost, proxyPort, socksProxyHost and socksProxyPort. That's it. It worked.

Michael Klishin

unread,
May 19, 2020, 12:51:59 AM5/19/20
to rabbitmq-users
Thank you for reporting back to the list, even though multiple questions in the same thread is usually frowned upon on this list.

RabbitMQ client libraries need to be able to resolve hostnames and TCP connectivity to the target host(s), so if a SOCKS proxy configuration provides those things, there really isn't much else to configure.

To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/be9c4e8d-9796-427b-848a-8499812684ee%40googlegroups.com.

Baljeet Kumar

unread,
Oct 18, 2021, 8:14:43 AM10/18/21
to rabbitmq-users
HI @Ashok - if possible can you please share a snap shot on what you changed on java code to make it work.. we are struggling on same for quite some time and no luck so far.
Reply all
Reply to author
Forward
0 new messages