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(); } }