66 "encoding/json"
77 "io"
88 "os"
9+ "time"
910
1011 "github.com/pkg/errors"
1112)
@@ -22,12 +23,18 @@ type Identify struct {
2223 // UserAgent represents the type of the client, by default it is set to
2324 // nsq.DefaultUserAgent.
2425 UserAgent string
26+
27+ // MessageTimeout can bet set to configure the server-side message timeout
28+ // for messages delivered to this consumer. By default it is not sent to
29+ // the server.
30+ MessageTimeout time.Duration
2531}
2632
2733type identifyBody struct {
28- ClientID string `json:"client_id,omitempty"`
29- Hostname string `json:"hostname,omitempty"`
30- UserAgent string `json:"user_agent,omitempty"`
34+ ClientID string `json:"client_id,omitempty"`
35+ Hostname string `json:"hostname,omitempty"`
36+ UserAgent string `json:"user_agent,omitempty"`
37+ MessageTimeout int `json:"msg_timeout,omitempty"`
3138}
3239
3340// Name returns the name of the command in order to satisfy the Command
@@ -42,9 +49,10 @@ func (c Identify) Write(w *bufio.Writer) (err error) {
4249 var data []byte
4350
4451 if data , err = json .Marshal (identifyBody {
45- ClientID : c .ClientID ,
46- Hostname : c .Hostname ,
47- UserAgent : c .UserAgent ,
52+ ClientID : c .ClientID ,
53+ Hostname : c .Hostname ,
54+ UserAgent : c .UserAgent ,
55+ MessageTimeout : int (c .MessageTimeout / time .Millisecond ),
4856 }); err != nil {
4957 return
5058 }
@@ -75,9 +83,10 @@ func readIdentify(r *bufio.Reader) (cmd Identify, err error) {
7583 }
7684
7785 cmd = Identify {
78- ClientID : body .ClientID ,
79- Hostname : body .Hostname ,
80- UserAgent : body .UserAgent ,
86+ ClientID : body .ClientID ,
87+ Hostname : body .Hostname ,
88+ UserAgent : body .UserAgent ,
89+ MessageTimeout : time .Millisecond * time .Duration (body .MessageTimeout ),
8190 }
8291 return
8392}
0 commit comments