本文整理汇总了Golang中proto-ascent/msg.Header.GetMessageId方法的典型用法代码示例。如果您正苦于以下问题:Golang Header.GetMessageId方法的具体用法?Golang Header.GetMessageId怎么用?Golang Header.GetMessageId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类proto-ascent/msg.Header
的用法示例。
在下文中一共展示了Header.GetMessageId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CloseMessage
// CloseMessage releases a message header.
//
// header: Message header.
//
// Returns nil on success.
func (this *Messenger) CloseMessage(header *msgpb.Header) error {
if header.GetMessengerId() != this.uid {
this.Errorf("message header %s is not created by this messenger", header)
return errs.ErrInvalid
}
if header.Request == nil {
return nil
}
//
// Remove the request and its response channel from live requests map.
//
lock, errLock := this.ctlr.Lock("this.requestMap")
if errLock != nil {
return errLock
}
defer lock.Unlock()
requestID := header.GetMessageId()
responseCh, found := this.requestMap[requestID]
if !found {
return nil
}
close(responseCh)
delete(this.requestMap, requestID)
return nil
}
示例2: Receive
// Receive waits for a response to a live request.
//
// request: Message header of a live request.
//
// Returns response message header and response data on success.
func (this *Messenger) Receive(request *msgpb.Header) (*msgpb.Header,
[]byte, error) {
timeout := msg.RequestTimeout(request)
lock, errLock := this.ctlr.TimedLock(timeout, "this.requestMap")
if errLock != nil {
return nil, nil, errLock
}
defer lock.Unlock()
requestID := request.GetMessageId()
responseCh, found := this.requestMap[requestID]
if !found {
this.Errorf("no live request [%s] exist", request)
return nil, nil, errs.ErrNotExist
}
// Close the lock early to unblock others.
lock.Unlock()
// Perform a non-blocking receive if timeout is zero.
if timeout == 0 {
select {
case entry := <-responseCh:
return entry.header, entry.data, nil
default:
return nil, nil, errs.ErrRetry
}
}
// Perform a blocking receive with a timeout.
select {
case <-time.After(timeout):
this.Warningf("timedout waiting for response to %s", request)
return nil, nil, errs.ErrTimeout
case entry := <-responseCh:
if entry == nil {
return nil, nil, errs.ErrRetry
}
return entry.header, entry.data, nil
}
}
示例3: NewResponse
// NewResponse creates a message header for a response message.
//
// request: Message header for the received request.
func (this *Messenger) NewResponse(request *msgpb.Header) *msgpb.Header {
header := this.NewPost()
header.Response = &msgpb.Header_Response{}
header.Response.RequestId = proto.Int64(request.GetMessageId())
return header
}