Я просто пытаюсь создать соединение с Rabbit, работающим через порт 5671 (5672: по умолчанию).
Мое соединение создано с использованием файла .properties, который содержит:
##RabbitMQ
spring.rabbitmq.host=url
spring.rabbitmq.port=5671
spring.rabbitmq.username=user
spring.rabbitmq.password=pass
spring.rabbitmq.ssl.enabled=false (i've changed the value = true)
spring.rabbitmq.virtualHost=virtualHost
ike.rabbitmq.exchange=exchange
ike.rabbitmq.routingkey=routingKey
ike.rabbitmq.queue=queue
#RabbitMQ Consumer
ike.rabbitmq.queue.c=consumerQueue
И класс с аннотациями @Bean:
@Component
public class Producer {
@Autowired
private RabbitTemplate rabbitTemplate;
@Value("${spring.rabbitmq.host}")
private String host;
@Value("${spring.rabbitmq.port}")
private int port;
@Value("${spring.rabbitmq.username}")
private String user;
@Value("${spring.rabbitmq.password}")
private String pass;
@Value("${spring.rabbitmq.virtualHost}")
private String virtualHost;
@Value("${ike.rabbitmq.exchange}")
private String exchange;
@Value("${ike.rabbitmq.routingkey}")
private String routingKey;
@Value("${ike.rabbitmq.queue}")
private String queue;
@Value("${rabbitmq.use-ssl:false}")
boolean useSSL;
public void sendMsg(Object msg) {
rabbitTemplate.convertAndSend(exchange, routingKey, msg);
}
@Bean
Queue queue() {return new Queue(queue, true);}
@Bean
TopicExchange exchange() {return new TopicExchange(exchange);}
@Bean
Binding binding (Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(routingKey);
}
@Bean
public RabbitTemplate rabbitTemplate(final ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setMessageConverter(producerJackson2MessageConverter());
return rabbitTemplate;
}
@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter() {
return new Jackson2JsonMessageConverter();
}
}
Проблема в том, что каждый раз, когда я запускаю свой проект, соединение сбрасывается. Кто-то сказал мне, что я должен создать что-то вроде:
ConnectionFactory connection = new ConnectionFactory();
connection.useSslProtocol();
но это было бы в экземпляре ConnectionFactory, если я не ошибаюсь
2020-03-26 11:11:28.626 INFO 62454 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [domain.com:5671]
2020-03-26 11:11:28.702 WARN 62454 --- [116.44.217:5671] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Connection reset)
2020-03-26 11:11:28.705 INFO 62454 --- [ main] o.s.a.r.l.SimpleMessageListenerContainer : Broker not available; cannot force queue declarations during start: java.io.IOException
2020-03-26 11:11:33.810 INFO 62454 --- [ntContainer#0-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@77b17867: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2020-03-26 11:11:33.812 INFO 62454 --- [ntContainer#0-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [domain.com:5671]
2020-03-26 11:11:33.852 WARN 62454 --- [116.44.217:5671] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Connection reset)
2020-03-26 11:11:38.891 INFO 62454 --- [ntContainer#0-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@3e59186: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2020-03-26 11:11:38.892 INFO 62454 --- [ntContainer#0-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [domain.com:5671]
2020-03-26 11:11:38.946 WARN 62454 --- [116.44.217:5671] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Connection reset)
Большое спасибо!