當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Header.GetMessageId方法代碼示例

本文整理匯總了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
}
開發者ID:bvk,項目名稱:ascent,代碼行數:33,代碼來源:messenger.go

示例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
	}
}
開發者ID:bvk,項目名稱:ascent,代碼行數:49,代碼來源:messenger.go

示例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
}
開發者ID:bvk,項目名稱:ascent,代碼行數:9,代碼來源:messenger.go


注:本文中的proto-ascent/msg.Header.GetMessageId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。