连接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吗?

0
4
精慕门8147235
回复
幕布斯5172899
请问如何启动呢
2023-06-18
共4条回复

SpringBoot 在线协同办公小程序开发 全栈式项目实战

未来趋势型业务 + 前后端综合技术栈 + 惊艳的细节打磨

1802 学习 · 1919 问题

查看课程