Helius
2021-02-28 d8d653b40cc6565c72cccd28de831474e5d5c512
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.xcong.excoin.configurations.listener;
 
import com.alibaba.fastjson.JSONObject;
import com.huobi.client.model.event.TradeEvent;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import com.xcong.excoin.rabbit.pricequeue.WebsocketPriceService;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * @author wzy
 * @date 2021-02-25
 **/
@Slf4j
@Component
public class RedisReceiver implements MessageListener {
 
    @Resource
    private RedisUtils redisUtils;
 
    @Resource
    private SymbolsService symbolsService;
 
    @Resource
    private WebsocketPriceService websocketPriceService;
 
    @Override
    public void onMessage(Message message, byte[] bytes) {
        String data = message.toString().replaceAll("\"", "");
        String[] dataArr = data.split("_");
 
        String symbol = dataArr[0];
        String price = dataArr[1];
 
        redisUtils.set(CoinTypeConvert.convertToKey(symbol), price);
        // 比较
        websocketPriceService.comparePriceAsc(symbol, price);
        websocketPriceService.comparePriceDesc(symbol, price);
        websocketPriceService.wholeBomb();
    }
}