@@ -761,7 +761,7 @@ func (p *protocolV2) PUB(client *clientV2, params [][]byte) ([]byte, error) {
761761 }
762762
763763 topic := p .ctx .nsqd .GetTopic (topicName )
764- msg := NewMessage (<- p . ctx . nsqd . idChan , messageBody )
764+ msg := NewMessage (topic . GenerateID () , messageBody )
765765 err = topic .PutMessage (msg )
766766 if err != nil {
767767 return nil , protocol .NewFatalClientErr (err , "E_PUB_FAILED" , "PUB failed " + err .Error ())
@@ -783,6 +783,12 @@ func (p *protocolV2) MPUB(client *clientV2, params [][]byte) ([]byte, error) {
783783 fmt .Sprintf ("E_BAD_TOPIC MPUB topic name %q is not valid" , topicName ))
784784 }
785785
786+ if err := p .CheckAuth (client , "MPUB" , topicName , "" ); err != nil {
787+ return nil , err
788+ }
789+
790+ topic := p .ctx .nsqd .GetTopic (topicName )
791+
786792 bodyLen , err := readLen (client .Reader , client .lenSlice )
787793 if err != nil {
788794 return nil , protocol .NewFatalClientErr (err , "E_BAD_BODY" , "MPUB failed to read body size" )
@@ -798,18 +804,12 @@ func (p *protocolV2) MPUB(client *clientV2, params [][]byte) ([]byte, error) {
798804 fmt .Sprintf ("MPUB body too big %d > %d" , bodyLen , p .ctx .nsqd .getOpts ().MaxBodySize ))
799805 }
800806
801- messages , err := readMPUB (client .Reader , client .lenSlice , p . ctx . nsqd . idChan ,
807+ messages , err := readMPUB (client .Reader , client .lenSlice , topic ,
802808 p .ctx .nsqd .getOpts ().MaxMsgSize )
803809 if err != nil {
804810 return nil , err
805811 }
806812
807- if err := p .CheckAuth (client , "MPUB" , topicName , "" ); err != nil {
808- return nil , err
809- }
810-
811- topic := p .ctx .nsqd .GetTopic (topicName )
812-
813813 // if we've made it this far we've validated all the input,
814814 // the only possible error is that the topic is exiting during
815815 // this next call (and no messages will be queued in that case)
@@ -873,7 +873,7 @@ func (p *protocolV2) DPUB(client *clientV2, params [][]byte) ([]byte, error) {
873873 }
874874
875875 topic := p .ctx .nsqd .GetTopic (topicName )
876- msg := NewMessage (<- p . ctx . nsqd . idChan , messageBody )
876+ msg := NewMessage (topic . GenerateID () , messageBody )
877877 msg .deferred = timeoutDuration
878878 err = topic .PutMessage (msg )
879879 if err != nil {
@@ -910,7 +910,7 @@ func (p *protocolV2) TOUCH(client *clientV2, params [][]byte) ([]byte, error) {
910910 return nil , nil
911911}
912912
913- func readMPUB (r io.Reader , tmp []byte , idChan chan MessageID , maxMessageSize int64 ) ([]* Message , error ) {
913+ func readMPUB (r io.Reader , tmp []byte , topic * Topic , maxMessageSize int64 ) ([]* Message , error ) {
914914 numMessages , err := readLen (r , tmp )
915915 if err != nil {
916916 return nil , protocol .NewFatalClientErr (err , "E_BAD_BODY" , "MPUB failed to read message count" )
@@ -945,7 +945,7 @@ func readMPUB(r io.Reader, tmp []byte, idChan chan MessageID, maxMessageSize int
945945 return nil , protocol .NewFatalClientErr (err , "E_BAD_MESSAGE" , "MPUB failed to read message body" )
946946 }
947947
948- messages = append (messages , NewMessage (<- idChan , msgBody ))
948+ messages = append (messages , NewMessage (topic . GenerateID () , msgBody ))
949949 }
950950
951951 return messages , nil
0 commit comments