Exemplo n.º 1
0
func NewWorkd(o *cfg.Options) (w *Workd) {
	w = new(Workd)
	w.options = o
	var err error
	w.reader, err = nsq.NewReader(o.MsgTopic, o.MsgChannel)
	if err != nil {
		log.Fatalf("Creating a reader failed: %s", err)
	}
	return
}
Exemplo n.º 2
0
func (ni *NsqInput) Init(config interface{}) error {
	ni.conf = config.(*NsqInputConfig)
	ni.stopChan = make(chan bool)
	var err error
	ni.nsqReader, err = nsq.NewReader(ni.conf.Topic, ni.conf.Channel)
	if err != nil {
		//log.Fatalf(err.Error())
		panic(err)
	}
	ni.nsqReader.SetMaxInFlight(1000)
	ni.handler = &MyTestHandler{logChan: make(chan *Message)}
	ni.nsqReader.AddAsyncHandler(ni.handler)
	return nil
}
Exemplo n.º 3
0
// Result waits for a result to be published on the given topic and channel,
// deserializing it into a TaskResult via the TaskFeedbackHandler. After
// the task result is obtained the topic and channel are deleted.
func (self *Taskd) Result(topic, channel string) (result *task.TaskResult, err error) {
	// Create a reader and give it a handler. Since this invoker
	// created the unique topic no one else is listening on it
	nsqReader, err := nsq.NewReader(topic, channel)
	if err != nil {
		return
	}

	handler := &task.TaskFeedbackHandler{TaskResults: make(chan *task.TaskResult)}
	nsqReader.AddHandler(handler)
	err = nsqReader.ConnectToLookupd(self.options.MsgSourceHttpAddr)
	if err != nil {
		return
	}

	result = <-handler.TaskResults
	err = msg.DeleteTopic(topic, self.options.MsgSourceHttpAddr)
	return
}