连接mq,系统提示超时,Connection timed out
来源:9-12 执行系统消息异步收发(一)

幕布斯5172899
2022-01-23
您好,如题
@Configuration
public class RabbitMQConfig {
@Bean
public ConnectionFactory getFactory(){
ConnectionFactory factory=new ConnectionFactory();
factory.setHost(“192.168.2.111”);
factory.setPort(5672);
return factory;
}
}
public void send(String topic, MessageEntity entity){
String id=messageService.insertMessage(entity);
try(Connection connection=factory.newConnection();
Channel channel=connection.createChannel();
){
channel.queueDeclare(topic,true,false,false,null);
HashMap map=new HashMap();
map.put("messageId",id);
AMQP.BasicProperties properties=new AMQP.BasicProperties().builder().headers(map).build();
channel.basicPublish("",topic,properties,entity.getMsg().getBytes(StandardCharsets.UTF_8));
log.debug("消息发送成功");
}catch (Exception e){
log.error("执行异常",e);
throw new EmosException("向MQ发送消息失败");
}
}
写回答
1回答
-
神思者
2022-01-23
你用的是课程附带的rabbitmq吗?
042023-06-18
相似问题