Helper to setup and send new request style requests. Return the chan to receive the response.
(subj string, hdr, data []byte)
| 4580 | |
| 4581 | // Helper to setup and send new request style requests. Return the chan to receive the response. |
| 4582 | func (nc *Conn) createNewRequestAndSend(subj string, hdr, data []byte) (chan *Msg, string, error) { |
| 4583 | nc.mu.Lock() |
| 4584 | // Create new literal Inbox and map to a chan msg. |
| 4585 | mch := make(chan *Msg, RequestChanLen) |
| 4586 | respInbox := nc.newRespInbox() |
| 4587 | token := respInbox[nc.respSubLen:] |
| 4588 | |
| 4589 | nc.respMap[token] = mch |
| 4590 | if nc.respMux == nil { |
| 4591 | // Create the response subscription we will use for all new style responses. |
| 4592 | // This will be on an _INBOX with an additional terminal token. The subscription |
| 4593 | // will be on a wildcard. |
| 4594 | s, err := nc.subscribeLocked(nc.respSub, _EMPTY_, nc.respHandler, nil, nil, false, nil) |
| 4595 | if err != nil { |
| 4596 | nc.mu.Unlock() |
| 4597 | return nil, token, err |
| 4598 | } |
| 4599 | nc.respMux = s |
| 4600 | } |
| 4601 | nc.mu.Unlock() |
| 4602 | |
| 4603 | if err := nc.publish(subj, respInbox, false, hdr, data); err != nil { |
| 4604 | return nil, token, err |
| 4605 | } |
| 4606 | |
| 4607 | return mch, token, nil |
| 4608 | } |
| 4609 | |
| 4610 | // RequestMsg will send a request payload including optional headers and deliver |
| 4611 | // the response message, or an error, including a timeout if no message was received properly. |
no test coverage detected