From b6379cc528bb058cbeeaa50c39a0170244db7ff4 Mon Sep 17 00:00:00 2001 From: Clement Li Date: Tue, 2 Nov 2021 17:43:44 +0800 Subject: [PATCH] fix autoAck --- src/gitee-utils/message.go | 5 +---- src/server.go | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/gitee-utils/message.go b/src/gitee-utils/message.go index b7047e1..0ac956b 100644 --- a/src/gitee-utils/message.go +++ b/src/gitee-utils/message.go @@ -216,7 +216,7 @@ func (c *Consumer) consume(channel *amqp.Channel, id int) { msgs, err := channel.Consume( c.config.QueueName, fmt.Sprintf("%s (%d/%d)", c.config.ConsumerName, id, c.config.ConsumerCount), - false, + true, false, false, false, @@ -231,15 +231,12 @@ func (c *Consumer) consume(channel *amqp.Channel, id int) { log.Println("[", id, "] Running ...") log.Println("[", id, "] Press CTRL+C to exit ...") - forever := make(chan bool) for msg := range msgs { err := eventHandler(msg) if err != nil { log.Println("something wrong with executor", err) } } - <-forever - log.Println("[", id, "] Exiting ...") } diff --git a/src/server.go b/src/server.go index f2ae786..58c196e 100644 --- a/src/server.go +++ b/src/server.go @@ -2,7 +2,6 @@ package main import ( "log" - "os" "time" gitee_utils "gitee.com/lizi/test-bot/src/gitee-utils" @@ -10,24 +9,24 @@ import ( func doRabbitMQ() { - RMQ_QUEUE_NAME := os.Getenv("RMQ_QUEUE_NAME") - RMQ_HOST := os.Getenv("RMQ_HOST") - RMQ_VHOST := os.Getenv("RMQ_VHOST") - RMQ_USER := os.Getenv("RMQ_USER") - RMQ_PASS := os.Getenv("RMQ_PASS") - RMQ_PORT := os.Getenv("RMQ_PORT") - RMQ_ROUTINGKEY := os.Getenv("RMQ_ROUTINGKEY") - RMQ_EXCHANGE_NAME := os.Getenv("RMQ_EXCHANGE_NAME") - RMQ_EXCHANGE_TYPE := os.Getenv("RMQ_EXCHANGE_TYPE") + // RMQ_QUEUE_NAME := os.Getenv("RMQ_QUEUE_NAME") + // RMQ_HOST := os.Getenv("RMQ_HOST") + // RMQ_VHOST := os.Getenv("RMQ_VHOST") + // RMQ_USER := os.Getenv("RMQ_USER") + // RMQ_PASS := os.Getenv("RMQ_PASS") + // RMQ_PORT := os.Getenv("RMQ_PORT") + // RMQ_ROUTINGKEY := os.Getenv("RMQ_ROUTINGKEY") + // RMQ_EXCHANGE_NAME := os.Getenv("RMQ_EXCHANGE_NAME") + // RMQ_EXCHANGE_TYPE := os.Getenv("RMQ_EXCHANGE_TYPE") // RabbitMQ rc := gitee_utils.RabbitConfig{ Schema: "amqp", - Username: RMQ_USER, - Password: RMQ_PASS, - Host: RMQ_HOST, - Port: RMQ_PORT, - VHost: RMQ_VHOST, + Username: "guest", + Password: "guest", + Host: "140.83.83.152", + Port: "8090", + VHost: "", ConnectionName: "", } rbt := gitee_utils.NewRabbit(rc) @@ -37,10 +36,10 @@ func doRabbitMQ() { // Consumer cc := gitee_utils.ConsumerConfig{ - ExchangeName: RMQ_EXCHANGE_NAME, - ExchangeType: RMQ_EXCHANGE_TYPE, - RoutingKey: RMQ_ROUTINGKEY, - QueueName: RMQ_QUEUE_NAME, + ExchangeName: "lz.direct", + ExchangeType: "direct", + RoutingKey: "lz.issue", + QueueName: "lz.issue", ConsumerCount: 1, PrefetchCount: 1, } -- Gitee