前言
本文是一个简单的rabbitmq工具类, 带连接池复用了connection. 其中配置参数从apollo设置的, 这里可以写死, 或者从配置文件中读取.
代码
@Configuration
@EnableApolloConfig
public class MqUtil {
private final List<Connection> connections = new ArrayList<>();
private final int maxConnection = 20;
@Value("${mq.calltopay.rabbit.host}")
private String host;
@Value("${mq.calltopay.rabbit.port}")
private int port;
@Value("${mq.calltopay.rabbit.username}")
private String username;
@Value("${mq.calltopay.rabbit.password}")
private String password;
@Autowired
@Qualifier("mqConnectionFactory")
public ConnectionFactory factory;
@Bean(name = "mqConnectionFactory")
public ConnectionFactory getRabbitMqConnection() {
return