本文整理匯總了Golang中github.com/absolute8511/nsq/nsqd.ClientV2.SendingMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang ClientV2.SendingMessage方法的具體用法?Golang ClientV2.SendingMessage怎麽用?Golang ClientV2.SendingMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/absolute8511/nsq/nsqd.ClientV2
的用法示例。
在下文中一共展示了ClientV2.SendingMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: messagePump
//.........這裏部分代碼省略.........
flusherChan = outputBufferTicker.C
}
select {
case <-client.ExitChan:
goto exit
case <-flusherChan:
// if this case wins, we're either starved
// or we won the race between other channels...
// in either case, force flush
client.LockWrite()
err = client.Flush()
client.UnlockWrite()
if err != nil {
goto exit
}
flushed = true
case <-client.ReadyStateChan:
case subChannel = <-subEventChan:
// you can't SUB anymore
nsqd.NsqLogger().Logf("client %v sub to channel: %v", client.ID,
subChannel.GetName())
subEventChan = nil
case identifyData := <-identifyEventChan:
// you can't IDENTIFY anymore
identifyEventChan = nil
outputBufferTicker.Stop()
if identifyData.OutputBufferTimeout > 0 {
outputBufferTicker = time.NewTicker(identifyData.OutputBufferTimeout)
}
heartbeatTicker.Stop()
heartbeatChan = nil
if identifyData.HeartbeatInterval > 0 {
heartbeatTicker = time.NewTicker(identifyData.HeartbeatInterval)
heartbeatChan = heartbeatTicker.C
}
if identifyData.SampleRate > 0 {
sampleRate = identifyData.SampleRate
}
msgTimeout = identifyData.MsgTimeout
case <-heartbeatChan:
if subChannel != nil && client.IsReadyForMessages() {
// try wake up the channel
subChannel.TryWakeupRead()
}
err = Send(client, frameTypeResponse, heartbeatBytes)
nsqd.NsqLogger().LogDebugf("PROTOCOL(V2): [%s] send heartbeat", client)
if err != nil {
heartbeatFailedCnt++
nsqd.NsqLogger().LogWarningf("PROTOCOL(V2): [%s] send heartbeat failed %v times, %v", client, heartbeatFailedCnt, err)
if heartbeatFailedCnt > 2 {
goto exit
}
} else {
heartbeatFailedCnt = 0
}
case msg, ok := <-clientMsgChan:
if !ok {
goto exit
}
if sampleRate > 0 && rand.Int31n(100) > sampleRate {
// FIN automatically, all message will not wait to confirm if not sending,
// and the reader keep moving forward.
offset, _, _, _ := subChannel.ConfirmBackendQueue(msg)
// TODO: sync to replica nodes.
_ = offset
continue
}
// avoid re-send some confirmed message,
// this may happen while the channel reader is reset to old position
// due to some retry or leader change.
if subChannel.IsConfirmed(msg) {
continue
}
subChannel.StartInFlightTimeout(msg, client.ID, client.String(), msgTimeout)
client.SendingMessage()
err = SendMessage(client, msg, &buf, subChannel.IsOrdered())
if err != nil {
goto exit
}
flushed = false
}
}
exit:
nsqd.NsqLogger().LogDebugf("PROTOCOL(V2): [%s] exiting messagePump", client)
heartbeatTicker.Stop()
outputBufferTicker.Stop()
if err != nil {
nsqd.NsqLogger().Logf("PROTOCOL(V2): [%s] messagePump error - %s", client, err)
}
close(stoppedChan)
}