1、在pom文件中引入amqp的jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
2、在application.properties中添加配置文件
spring.rabbitmq.host=183.230.102.49
spring.rabbitmq.port=1257
spring.rabbitmq.username=15001317409
spring.rabbitmq.password=201808037409
3、监听器监听指定的Queue
//监听器监听指定的Queue
@RabbitListener(queues="xMat.toOtherIndu.15001317409")
@RabbitHandler
public void process2(Message message) {
System.out.println("messages:"+message.getBody());
String s;
try {
s = new String(message.getBody(), "UTF-8");
logger.info("------>MQ接收到的数据:"+s);
System.out.println("------>MQ接收到的数据:"+s);
JSONObject json= JSONObject.fromObject(s);
String msgType = String.valueOf(json.get("msgType"));
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String[] msgtype = MsgType.MSG_TYPE.split(",");
List<String> msgtypelist = Arrays.asList(msgtype);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}