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

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

使用 Go-Stomp 緩存 ActiveMQ 連接

使用 Go-Stomp 緩存 ActiveMQ 連接

Go
慕森卡 2021-12-20 16:40:38
使用 Go-Stomp,可以使用以下代碼獲取連接。if conn, err = stomp.Dial("tcp",        Broker.URI,        stomp.ConnOpt.Login(Broker.User, Broker.Password)); err != nil {        panic(fmt.Sprintf("Could not connect to ActiveMQ using brokerUri %v. Can not continue.", Broker.URI))    }連接是否可以緩存以重復(fù)使用以發(fā)送不同請(qǐng)求的消息?還是每次要發(fā)送消息時(shí)都需要獲取連接?后來(lái)聽(tīng)起來(lái)效率低下。連接實(shí)例上的Send方法會(huì)在出現(xiàn)故障時(shí)關(guān)閉連接。因此,如果我們緩存它,則必須檢查連接是否仍然存在以供后續(xù)發(fā)送消息調(diào)用。但是我沒(méi)有找到檢查連接是否關(guān)閉的方法?Conn結(jié)構(gòu)具有封閉成員,但這不會(huì)通過(guò)任何方法公開。// A Conn is a connection to a STOMP server. Create a Conn using either// the Dial or Connect function.type Conn struct {    conn         io.ReadWriteCloser    readCh       chan *frame.Frame    writeCh      chan writeRequest    version      Version    session      string    server       string    readTimeout  time.Duration    writeTimeout time.Duration    closed       bool    options      *connOptions}
查看完整描述

2 回答

?
慕的地6264312

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

您可以重復(fù)使用,直到發(fā)生故障的連接,見(jiàn)例如從細(xì)末跺腳例子。


沒(méi)有辦法測(cè)試是否打開。


在圖書館本身中,他們?cè)谧x取時(shí)吃錯(cuò)誤,但在發(fā)送時(shí)不會(huì):


if err != nil {

        if err == io.EOF {

            log.Println("connection closed:", c.rw.RemoteAddr())


查看完整回答
反對(duì) 回復(fù) 2021-12-20
?
守著星空守著你

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

我添加了代碼來(lái)處理失敗并檢查特定錯(cuò)誤。


if err := conn.Send(queue, "text/plain", []byte(message)); err != nil {

            if err == stomp.ErrAlreadyClosed {

                log.Println("ActiveMQ Connection is in closed state. Reconnecting ...")

                conn = ConnectToBroker()

                err = conn.Send(queue, "text/plain", []byte(message))

            }

            if err != nil {

                log.Printf("Failed to send message to Queue %v.  Error is %v, Payload is %v", queue, err.Error(), message)

            }

            return err

        }

    }


查看完整回答
反對(duì) 回復(fù) 2021-12-20
  • 2 回答
  • 0 關(guān)注
  • 237 瀏覽
慕課專欄
更多

添加回答

舉報(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)