【发布时间】:2020-06-06 17:07:59
【问题描述】:
我有一个 rabbitmq 在我的 ec2 实例中运行。我有两个 springboot 应用程序一个将消息推送到队列。我使用了第一个连接工厂来推入队列,它工作正常
connectionFactory.setUri("amqp://guest:guest@ec2host:5672/%2F");
第二个尝试连接到rabbitmq stomp端口,像这样
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/topic").setRelayHost("ec2host").setRelayPort(61613).setClientLogin("guest")
.setClientPasscode("guest");
当我运行代码时,它运行但不断抛出此错误消息
Attempting to connect to: [localhost:5672]
Consumer raised exception, processing can restart if the connection factory supports it.
Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException:
Connection refused (Connection refused)
2020-06-06 22:34:10.030 INFO 19749 --- [tContainer#0-85]
o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer@71f987d1: tags=[[]],
channel=null, acknowledgeMode=AUTO local queue size=0
2020-06-06 22:34:10.030 INFO 19749 --- [tContainer#0-86] o.s.a.r.c.CachingConnectionFactory
我不知道为什么它会尝试连接 localhost:5672,尽管我将设置主机保存到 ec2。
监听队列的类
public class MessageRedirect {
@Autowired
private SimpMessageSendingOperations messagingTemplate;
@RabbitListener(queues = "upload-queue")
@SendTo("/{institution}/notification")
public String sendNotification(String notification) throws JsonMappingException, JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
Notification not = objectMapper.readValue(notification, Notification.class);
//messagingTemplate.convertAndSend("/topic/"+not.getInstitution(), not.getMessage());
messagingTemplate.convertAndSend("/topic/"+not.getInstitution() + ".student", not.getMessage());
System.out.println("SENDING MESSAGE TO upload-queue" + "/"+ not.getInstitution()+"/notification");
return "NOTIFICATION SENT";
}
}
【问题讨论】:
标签: amazon-ec2 websocket rabbitmq