第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么 RabbitMQ 的 PublishWithContext 不適用于 Go?

為什么 RabbitMQ 的 PublishWithContext 不適用于 Go?

Go
紅糖糍粑 2023-03-07 14:27:49
我正在通過(guò)在 GoLang 中構(gòu)建一個(gè)小型應(yīng)用程序來(lái)學(xué)習(xí) RabbitMQ - 在此處遵循此示例: https: //www.rabbitmq.com/tutorials/tutorial-one-go.html。我的項(xiàng)目具有以下結(jié)構(gòu):project└───cmd│   └───api│   │   main.go│   └───internal│   │   rabbitmq.go在cmd/internal/rabbitmq.go我有以下代碼 - (錯(cuò)誤是錯(cuò)誤的):import (    ...    amqp "github.com/rabbitmq/amqp091-go")func NewRabbitMQ() (*RabbitMQ, error) {    // Initialise connection to RabbitMQ    conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")    // Initialise Channel    ch, err := conn.Channel()     // Initialise Queue    q, err := ch.QueueDeclare(        "hello", // name        false,   // durable        false,   // delete when unused        false,   // exclusive        false,   // no-wait        nil,     // arguments    )    // Set Context    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)    defer cancel()    body := "Hello World!"    err = ch.PublishWithContext( // errors here       ctx,    // context       "",     // exchange       q.Name, // routing key       false,  // mandatory       false,  // immediate       amqp.Publishing{          ContentType: "text/plain",          Body:        []byte(body),       })    return &RabbitMQ{}, nil}據(jù)我所知,根據(jù)文檔,這是應(yīng)該如何實(shí)現(xiàn)的,所以我不確定為什么會(huì)出錯(cuò)。我曾嘗試使用谷歌搜索來(lái)尋找解決此問(wèn)題的幫助,但無(wú)濟(jì)于事。我正在使用 Go 1.19,也許這是一個(gè)問(wèn)題?
查看完整描述

1 回答

?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

這是一個(gè)簡(jiǎn)單的修復(fù)!問(wèn)題是我使用的 RabbitMQ 版本較舊,所以我只需要更改我的go.mod版本:

require github.com/rabbitmq/amqp091-go v1.1.0

到:

require github.com/rabbitmq/amqp091-go v1.4.0


查看完整回答
反對(duì) 回復(fù) 2023-03-07
  • 1 回答
  • 0 關(guān)注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)