简体   繁体   English

Socks5 代理如何与 Spring Boot 集成以通过代码连接 AMQP - RabbitMQ

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

Basically I am trying to use SOCKS5 proxy to connect RabbitMq with Spring Boot project.基本上我正在尝试使用 SOCKS5 代理将 RabbitMq 与 Spring 引导项目连接起来。

I have created Custom Socket factory and connected to PostgreDB, in that case that connection object accepts SocketFactory as parameter like given below;我创建了自定义套接字工厂并连接到 PostgreDB,在这种情况下,连接 object 接受 SocketFactory 作为参数,如下所示;

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.可以请任何人帮忙,我们如何通过 SOCKS5 代理在 Spring 引导项目中连接 RabbitMq。

In project we use pretty standard ConnectorFactory beans and RabbitTemplate annotated methods like given below在项目中,我们使用非常标准的 ConnectorFactory bean 和 RabbitTemplate 注释方法,如下所示

@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!谢谢!

Solved解决了

Used RabbitConnectionFactoryBean class and gave socket factory there as param使用 RabbitConnectionFactoryBean class 并将套接字工厂作为参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM