##### Coverage Report - com.ctrip.apollo.biz.message.RedisMessageSender

Classes in this File | Line Coverage | Branch Coverage | Complexity
RedisMessageSender |
0% | 0/14
N/A | N/A
| 1.5;1.5

1 |  |
     package com.ctrip.apollo.biz.message;
2 |  |
3 |  |
     import com.dianping.cat.Cat;
4 |  |
     import com.dianping.cat.message.Message;
5 |  |
     import com.dianping.cat.message.Transaction;
6 |  |
7 |  |
     import org.slf4j.Logger;
8 |  |
     import org.slf4j.LoggerFactory;
9 |  |
     import org.springframework.data.redis.core.RedisTemplate;
10 |  |
11 |  |
     /**
12 |  |
      * @author Jason Song(song_s@ctrip.com)
13 |  |
      */
14 |  |
     public class RedisMessageSender implements MessageSender {
15 | 0 |
       private static final Logger logger = LoggerFactory.getLogger(RedisMessageSender.class);
16 |  |
       private RedisTemplate<String, String> redisTemplate;
17 |  |
18 |  |
       public RedisMessageSender(
19 | 0 |
           RedisTemplate<String, String> redisTemplate) {
20 | 0 |
         this.redisTemplate = redisTemplate;
21 | 0 |
       }
22 |  |
23 |  |
       @Override
24 |  |
       public void sendMessage(String message, String channel) {
25 | 0 |
         logger.info("Sending message {} to channel {}", message, channel);
26 | 0 |
         Transaction transaction = Cat.newTransaction("Apollo.AdminService", "RedisMessageSender");
27 |  |
         try {
28 | 0 |
           redisTemplate.convertAndSend(channel, message);
29 | 0 |
           transaction.setStatus(Message.SUCCESS);
30 | 0 |
         } catch (Throwable ex) {
31 | 0 |
           logger.error("Sending message to redis failed", ex);
32 | 0 |
           transaction.setStatus(ex);
33 |  |
         } finally {
34 | 0 |
           transaction.complete();
35 | 0 |
         }
36 | 0 |
       }
37 |  |
     }