nsq
nsq copied to clipboard
nsqd: support length 0 messages
Currently, length 0 messages are rejected in doPUB for the http protocol and PUB in protocol_v2.
nsqd's diskQueue reads/writes enforce only the message header size (not requiring body). Also, the go-nsq api allows NewMessage to be called with an empty body, and DecodeMessage would make sense to also support a length 0 body to allow for idempotence between the two funcs.
A length 0 message would allow signals to be passed through an nsq system.
consumer, err := nsq.NewConsumer("topic", "channel", nsq.NewConfig())
if err != nil {
// Handle error
}
consumer.AddHandler(nsq.HandlerFunc(func(message *nsq.Message) error {
// Check if the message body is empty
if len(message.Body) == 0 {
// Handle length 0 message
return nil // Acknowledge the message
}
// Process non-empty messages here
// ...
return nil // Acknowledge the message
}))
err = consumer.ConnectToNSQLookupd("nsqlookupd-address:4161")
if err != nil {
// Handle error
}
// Run the consumer
<-consumer.StopChan