1
zhang
1 天以前 23182f2c951df5fa55e70e30ff70ddaf91199a2e
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
package com.zy.acs.hex.consumer;
 
import com.rabbitmq.client.Channel;
import com.zy.acs.hex.constant.InfluxDBConstant;
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.consumer.listener.AbstractListener;
import com.zy.acs.hex.domain.Device;
import com.zy.acs.hex.utils.ReflectionUtils;
import com.zy.acs.hex.utils.StrUtils;
import com.zy.component.influxdb.service.InfluxDBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
 
/**
 * 消费者
 */
@Slf4j
@Component
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(name = RabbitConstant.TOPIC_QUEUE_DOWN, durable = RabbitConstant.DURABLE),
        exchange = @Exchange(name = RabbitConstant.TOPIC_EXCHANGE, type = RabbitConstant.TOPIC_EXCHANGE_TYPE),
        key = RabbitConstant.ROUTING_KEY_DOWN
))
public class DownMessageListener implements AbstractListener {
 
 
    @Autowired
    private InfluxDBService influxDBService;
 
 
    @RabbitHandler
    public void handle(Device msg, @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String routingKey, Channel channel) {
        log.info("routingKey:{},receive down message:{}", routingKey, msg);
        influxDBService.writeData(InfluxDBConstant.DEVICE_MEASUREMENT, StrUtils.getTagsByRoutingKey(routingKey), ReflectionUtils.convertBean2Map(msg));
    }
 
 
}