-
-
Save amdprophet/24f7d7eaab0dedf6a1ce131a34e7fdb0 to your computer and use it in GitHub Desktop.
Revisions
-
Rotenberg, Joshua revised this gist
Mar 16, 2016 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,11 @@ package main // This is a basic example of running an nsqd instance embedded. It creates // and runs an nsqd with all of the default options, and then produces // and consumes a single message. You are probably better off running a // standalone instance, but embedding it can simplify deployment and is // useful in testing. // See https://github.com/nsqio/nsq/blob/master/nsqd/options.go and // https://github.com/nsqio/nsq/blob/master/apps/nsqd/nsqd.go for // more details on how to configure an embedded nsqd instance. import ( "bytes" @@ -31,6 +32,8 @@ func main() { opts := nsqd.NewOptions() nsqd := nsqd.New(opts) nsqd.Main() // wait until we are told to continue and exit <-done nsqd.Exit() }() -
Rotenberg, Joshua revised this gist
Mar 16, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,8 +13,8 @@ import ( "log" "time" "github.com/nsqio/go-nsq" "github.com/nsqio/nsq/nsqd" ) func main() { @@ -28,8 +28,8 @@ func main() { // binary mainly wraps up the handling of command // line args and does something similar opts := nsqd.NewOptions() nsqd := nsqd.New(opts) nsqd.Main() <-done nsqd.Exit() -
joshrotenberg revised this gist
Nov 10, 2014 . 1 changed file with 13 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,31 +11,29 @@ package main import ( "bytes" "log" "time" "github.com/bitly/go-nsq" "github.com/bitly/nsq/nsqd" ) func main() { done := make(chan bool) // Run the embedded nsqd in a go routine go func() { // running an nsqd with all of the default options // (as if you ran it from the command line with no flags) // is literally these three lines of code. the nsqd // binary mainly wraps up the handling of command // line args and does something similar opts := nsqd.NewNSQDOptions() nsqd := nsqd.NewNSQD(opts) nsqd.Main() <-done nsqd.Exit() }() cfg := nsq.NewConfig() -
joshrotenberg revised this gist
Nov 10, 2014 . 1 changed file with 21 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,37 +2,41 @@ package main // This is a basic example of running an nsqd instance embedded. It creates // and runs an nsqd with all of the default options, and then produces // and consumes a single message. You are probably better off running a // standalone instance, but embedding it can simpllify deployment. // See https://github.com/bitly/nsq/blob/master/nsqd/options.go and // https://github.com/bitly/nsq/blob/master/apps/nsqd/nsqd.go for // more details on how to configure an embedded nsqd instance. import ( "bytes" "log" "time" "github.com/bitly/go-nsq" "github.com/bitly/nsq/nsqd" ) func runDefaultNSQD(done chan bool) { // running an nsqd with all of the default options (as if you // ran it from the command line with no flags) is literally // these three lines of code. the nsqd binary mainly wraps up // the handling of command line args and does something similar opts := nsqd.NewNSQDOptions() nsqd := nsqd.NewNSQD(opts) nsqd.Main() <-done nsqd.Exit() } func main() { done := make(chan bool) // Run the embedded nsqd in a go routine go runDefaultNSQD(done) cfg := nsq.NewConfig() // the message we'll send to ourselves @@ -43,8 +47,9 @@ func main() { if err != nil { log.Fatal(err) } // Publish a single message to the 'embedded' topic err = p.Publish("embedded", msg) if err != nil { log.Fatal(err) } @@ -54,21 +59,26 @@ func main() { if err != nil { log.Fatal(err) } // and a single handler that just checks that the message we // received matches the message we sent c.AddHandler(nsq.HandlerFunc(func(m *nsq.Message) error { if bytes.Compare(m.Body, msg) != 0 { log.Fatal("message didn't match:", string(m.Body)) } else { log.Println("message matched:", string(m.Body)) } return nil })) // Connect the consumer to the embedded nsqd instance c.ConnectToNSQD("localhost:4150") // Sleep a little to give everything time to start up and let // our producer and consumer run time.Sleep(250 * time.Millisecond) // tell the nsqd instance to exit done <- true } -
joshrotenberg revised this gist
Nov 10, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,9 +58,9 @@ func main() { // received matches the message we sent c.AddHandler(nsq.HandlerFunc(func(m *nsq.Message) error { if bytes.Compare(m.Body, msg) != 0 { //"one message" { log.Fatal("message didn't match:", string(m.Body)) } else { log.Println("message matched:", string(m.Body)) } return nil })) -
joshrotenberg revised this gist
Nov 10, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,6 @@ import ( func runDefaultNSQD() { signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) opts := nsqd.NewNSQDOptions() -
joshrotenberg revised this gist
Nov 10, 2014 . 1 changed file with 70 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,76 @@ package main // This is a basic example of running an nsqd instance embedded. It creates // and runs an nsqd with all of the default options, and then produces // and consumes a single message. // See https://github.com/bitly/nsq/blob/master/nsqd/options.go and // https://github.com/bitly/nsq/blob/master/apps/nsqd/nsqd.go for // more details on how to configure an embedded nsqd instance. import ( "bytes" "log" "os" "os/signal" "syscall" "time" "github.com/bitly/go-nsq" "github.com/bitly/nsq/nsqd" ) func runDefaultNSQD() { //rand.Seed(time.Now().UTC().UnixNano()) signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) opts := nsqd.NewNSQDOptions() nsqd := nsqd.NewNSQD(opts) nsqd.Main() <-signalChan nsqd.Exit() } func main() { // Run the embedded nsqd in a go routine go runDefaultNSQD() cfg := nsq.NewConfig() // the message we'll send to ourselves msg := []byte("the message") // Set up a Producer, pointing at the default host:port p, err := nsq.NewProducer("localhost:4150", cfg) if err != nil { log.Fatal(err) } // Publish a single message to the 'embedded' topic err = p.Publish("embedded", msg) //[]byte("one message")) if err != nil { log.Fatal(err) } // Now set up a consumer c, err := nsq.NewConsumer("embedded", "local", cfg) if err != nil { log.Fatal(err) } // and a single handler that just checks that the message we // received matches the message we sent c.AddHandler(nsq.HandlerFunc(func(m *nsq.Message) error { if bytes.Compare(m.Body, msg) != 0 { //"one message" { log.Fatal(m) } else { log.Println("sent and received:", string(m.Body)) } return nil })) // Connect the consumer to the embedded nsqd instance c.ConnectToNSQD("localhost:4150") // Sleep a little to give everything time to start up and let // our producer and consumer run time.Sleep(250 * time.Millisecond) } -
joshrotenberg created this gist
Nov 10, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ package main func main() { }