How Socks5 proxy can be integrated with Spring Boot to connect AMQP - RabbitMQ via code

528 views Asked by At

Basically I am trying to use SOCKS5 proxy to connect RabbitMq with Spring Boot project.

I have created Custom Socket factory and connected to PostgreDB , in that case that connection object accepts SocketFactory as parameter like given below;

Properties props = new Properties();
props.setProperty("user", "username");
props.setProperty("password", "password");
props.setProperty("socketFactory", DBSocketFactory.class.getName());
Connection conn = DriverManager.getConnection(url, props);
return conn;

Can anyonw please help, how we can achieve to connect RabbitMq in Spring Boot project via SOCKS5 proxy.

In project we use pretty standard ConnectorFactory beans and RabbitTemplate annotated methods like given below

@Bean(name = "default-rabbit-connection-factory")
    public ConnectionFactory defaultConnectionFactory() {

        RabbitConnectionDto defaultConnectionDto = rabbitConnectionProperty.getConnections().stream()
                .filter(con -> con.getName().equals("DEFAULT"))
                .findFirst()
                .orElse(null);

        if (defaultConnectionDto == null) {
            log.error("No default Rabbit Connection!!!");
            return null;
        }

        return getConnectionFactory(defaultConnectionDto);
    }

    @Bean(name = "defaultRabbitTemplate")
    public RabbitTemplate defaultRabbitTemplate() {
        return new RabbitTemplate(defaultConnectionFactory());
    }

Thanks!

1

There are 1 answers

1
Emrah On BEST ANSWER

Solved

Used RabbitConnectionFactoryBean class and gave socket factory there as param