zwl 5 年之前
父節點
當前提交
80e3a8173b
共有 4 個文件被更改,包括 19 次插入3 次删除
  1. 2 2
      busdriver/busdriver.go
  2. 2 1
      busdriver/testbus.go
  3. 12 0
      log/mtp2_if/mtp2_if_2020-06-08.log
  4. 3 0
      log/mtp2_if/mtp2_if_2020-06-09.log

+ 2 - 2
busdriver/busdriver.go

@@ -52,7 +52,7 @@ func (t *TestProc) process(topic string, queuename string, msg *string) {
 func MqConnect() error {
 	url := config.SerCfg.MqCfg.Url
 	var err error
-	if MqChannel == nil {
+	if MqChannel == nil || MqConn.IsClosed() {
 		MqConn, err = amqp.Dial(url)
 		if err != nil {
 			fmt.Printf("rabbitmq connect failed:%s\n", err)
@@ -173,7 +173,7 @@ func Publish(topic, msg string) error {
 // Receive 接收消息
 func Receive(topic, queuename string, processer MsgProcesser) error {
 	var err error
-	if MqChannel == nil {
+	if MqChannel == nil || MqConn.IsClosed() {
 		err = MqConnect()
 		if err != nil {
 			return err

+ 2 - 1
busdriver/testbus.go

@@ -29,7 +29,8 @@ func TestBus() {
 	go func() {
 		for {
 			for _, subinfo := range SubInfos {
-				Publish(subinfo.Topic, "test message")
+				msg := "test message:" + time.Now().Format("2006-01-02 15:04:05")
+				Publish(subinfo.Topic, msg)
 			}
 			time.Sleep(5 * time.Second)
 		}

+ 12 - 0
log/mtp2_if/mtp2_if_2020-06-08.log

@@ -0,0 +1,12 @@
+time="2020-06-08 16:44:32" level=info msg="|200|    594.055µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 16:44:48" level=info msg="|200|    169.473µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 16:45:04" level=info msg="|200|     240.73µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 16:46:51" level=info msg="|200|    231.647µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 16:46:57" level=info msg="|200|    572.316µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 16:47:03" level=info msg="|200|    200.908µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 18:04:21" level=info msg="|200|    398.986µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 18:05:26" level=info msg="|200|   3.656098ms|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 18:50:35" level=info msg="|200|    186.363µs|            ::1|POST /bus/busopt/MsgPublish" func=main.ginLoggerMiddleware.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:169"
+time="2020-06-08 18:52:13" level=debug msg="Shutdown service..." func=main.main file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:140"
+time="2020-06-08 18:52:13" level=error msg="Start service failed[http: Server closed]." func=main.main.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:130"
+time="2020-06-08 18:52:13" level=debug msg="Service stopped" func=main.main file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:153"

+ 3 - 0
log/mtp2_if/mtp2_if_2020-06-09.log

@@ -0,0 +1,3 @@
+time="2020-06-09 09:30:18" level=debug msg="Shutdown service..." func=main.main file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:140"
+time="2020-06-09 09:30:18" level=error msg="Start service failed[http: Server closed]." func=main.main.func1 file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:130"
+time="2020-06-09 09:30:18" level=debug msg="Service stopped" func=main.main file="/Users/wanghongliang/Repo/Muchinfo_Git/MTP20_IF/main.go:153"