1
zhang
昨天 d35e2accdca4b3762359231f4fe479c9538b6f6f
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
package com.zy.acs.hex.consumer;
 
import com.rabbitmq.client.Channel;
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.consumer.listener.AbstractListener;
import com.zy.component.influxdb.service.InfluxDBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
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;
 
import java.io.IOException;
 
/**
 * 消费者
 */
@Slf4j
@Component
@RabbitListener(bindings = @QueueBinding(
        value = @Queue(name = RabbitConstant.TOPIC_QUEUE_UP, durable = RabbitConstant.DURABLE),
        exchange = @Exchange(name = RabbitConstant.TOPIC_EXCHANGE, type = RabbitConstant.TOPIC_EXCHANGE_TYPE),
        key = RabbitConstant.ROUTING_KEY_UP
))
public class UpMessageListener implements AbstractListener {
 
 
 
    @Autowired
    private RabbitTemplate rabbitTemplate;
 
 
    @Autowired
    private InfluxDBService influxDBService;
 
 
    @RabbitHandler
    public void handle(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
        log.info("receive up message: {}" ,  msg);
        try {
            channel.basicAck(tag,true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 进入消息消费业务逻辑。
        //String data = new String(message.getBody());
        //log.info("收到消息:{}" ,data );
        //influxDBService.writeData();
    }
 
 
 
 
}