-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathRabbitMqController.java
More file actions
47 lines (41 loc) · 1.58 KB
/
Copy pathRabbitMqController.java
File metadata and controls
47 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.visualpathit.account.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.visualpathit.account.utils.RabbitMqUtil;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
@Controller
public class RabbitMqController {
@GetMapping("/user/rabbit")
public ModelAndView checkRabbitMqStatus() {
ModelAndView modelAndView = new ModelAndView();
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(RabbitMqUtil.getRabbitMqHost());
factory.setPort(Integer.parseInt(RabbitMqUtil.getRabbitMqPort()));
factory.setUsername(RabbitMqUtil.getRabbitMqUser());
factory.setPassword(RabbitMqUtil.getRabbitMqPassword());
Connection connection = null;
try {
connection = factory.newConnection();
if (connection.isOpen()) {
modelAndView.setViewName("rabbitmq");
} else {
modelAndView.setViewName("rabbitmq-error");
}
} catch (IOException | TimeoutException e) {
modelAndView.setViewName("rabbitmq-error");
} finally {
if (connection != null) {
try {
connection.close();
} catch (IOException e) {
// Log the exception if needed
}
}
}
return modelAndView;
}
}