Address issue #50.
[stompngo.git] / nack.go
blobca39e03c03ba39ca43c5b1a0c2698f57a87415db
1 //
2 // Copyright © 2011-2019 Guy M. Allard
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 package stompngo
19 import (
20 "fmt"
23 var _ = fmt.Println
26 Nack a STOMP 1.1+ message.
28 For Stomp 1.1 Headers must contain a "message-id" key and a "subscription"
29 header key.
32 For Stomp 1.2 Headers must contain a unique "id" header key.
35 See the specifications at http://stomp.github.com/ for details.
38 Disallowed for an established STOMP 1.0 connection, and EBADVERNAK is returned.
40 Example:
41 h := stompngo.Headers{stompngo.HK_MESSAGE_ID, "message-id1",
42 stompngo.HK_SUBSCRIPTION, "d2cbe608b70a54c8e69d951b246999fbc20df694"}
43 e := c.Nack(h)
44 if e != nil {
45 // Do something sane ...
49 func (c *Connection) Nack(h Headers) error {
50 c.log(NACK, "start", h, c.Protocol())
51 if !c.connected {
52 return ECONBAD
54 if c.Protocol() == SPL_10 {
55 return EBADVERNAK
57 e := checkHeaders(h, c.Protocol())
58 if e != nil {
59 return e
62 switch c.Protocol() {
63 case SPL_12:
64 if _, ok := h.Contains(HK_ID); !ok {
65 return EREQIDNAK
67 default: // SPL_11
68 if _, ok := h.Contains(HK_SUBSCRIPTION); !ok {
69 return EREQSUBNAK
71 if _, ok := h.Contains(HK_MESSAGE_ID); !ok {
72 return EREQMIDNAK
76 e = c.transmitCommon(NACK, h) // transmitCommon Clones() the headers
77 c.log(NACK, "end", h, c.Protocol())
78 return e