1
zhang
5 小时以前 49bd72038d6bae30a34c096f2cba8c5b11dbad8c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.zy.acs.hex.controller;
 
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.domain.Device;
import com.zy.component.influxdb.service.InfluxDBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@Slf4j
@RequestMapping(value = "/message")
public class TestController {
 
    @Autowired
    private RabbitTemplate rabbitTemplate;
 
 
    @Autowired
    private InfluxDBService influxDBService;
 
 
    /**
     * 发送消息test1
     *
     * @return
     */
    @GetMapping(value = "/test1")
    public void sendTest1() {
        Device device = new Device();
        //device.setEvent("online");
        //device.setDeviceId("123");
        device.setProtocol("212121212121212");
        String router = RabbitConstant.ROUTING_KEY_UP.replaceFirst("\\*", "123").replaceFirst("\\*", "online");
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, router, device);
    }
 
    /**
     * 发送消息test2
     *
     * @return
     */
    @GetMapping(value = "/test2")
    public void sendTest2() {
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, RabbitConstant.ROUTING_KEY_DOWN, "qswaqsaasas");
    }
 
 
    /**
     * 发送消息test2
     *
     * @return
     */
    @GetMapping(value = "/query")
    @ResponseBody
    public Object queryTest() {
       return influxDBService.queryData("select * from device order by time desc limit 10");
    }
 
}