()
| 16 | var ctx = context.Background() |
| 17 | |
| 18 | func main() { |
| 19 | fmt.Println("[Cache service]") |
| 20 | |
| 21 | // Redis connection |
| 22 | connR := redis.NewClient(&redis.Options{ |
| 23 | Addr: conf.RedisURL, |
| 24 | Password: "", // no password set |
| 25 | DB: 0, // use default DB |
| 26 | }) |
| 27 | |
| 28 | // RabbitMQ connection |
| 29 | connMQ, err := rabbit.GetConn(conf.RabbitURL) |
| 30 | if err != nil { |
| 31 | log.Fatalf("rabbit connection: %s", err) |
| 32 | } |
| 33 | defer connMQ.Close() |
| 34 | |
| 35 | err = connMQ.DeclareTopicExchange(conf.Exchange) |
| 36 | if err != nil { |
| 37 | log.Fatalf("declare exchange: %s", err) |
| 38 | } |
| 39 | |
| 40 | // Start a Rabbit consumer with a message processing handler. |
| 41 | connMQ.StartConsumer(conf.Exchange, conf.QueueCache, conf.KeyCache, func(d amqp.Delivery) bool { |
| 42 | return updateRedis(d, connR) |
| 43 | }) |
| 44 | |
| 45 | select {} |
| 46 | } |
| 47 | |
| 48 | // updateRedis updates Redis with a new Rabbit message. |
| 49 | func updateRedis(d amqp.Delivery, c *redis.Client) bool { |
nothing calls this directly
no test coverage detected