Browse Source

New not get

pull/4/head v0.2.0
lane-c-wagner 5 years ago
parent
commit
d9535c14ec
5 changed files with 46 additions and 12 deletions
  1. +40
    -6
      README.md
  2. +2
    -2
      consume.go
  3. +1
    -1
      examples/consumer/main.go
  4. +1
    -1
      examples/publisher/main.go
  5. +2
    -2
      publish.go

+ 40
- 6
README.md View File

@ -27,8 +27,31 @@ go get github.com/wagslane/go-rabbitmq
## 🚀 Quick Start Consumer
### Default options
```go
consumer, err := rabbitmq.GetConsumer(
consumer, err := rabbitmq.NewConsumer("amqp://user:pass@localhost")
if err != nil {
log.Fatal(err)
}
err = consumer.StartConsuming(
func(d rabbitmq.Delivery) bool {
log.Printf("consumed: %v", string(d.Body))
// true to ACK, false to NACK
return true
},
"my_queue",
[]string{"routing_key1", "routing_key2"}
)
if err != nil {
log.Fatal(err)
}
```
### With options
```go
consumer, err := rabbitmq.NewConsumer(
"amqp://user:pass@localhost",
// can pass nothing for no logging
func(opts *rabbitmq.ConsumerOptions) {
@ -56,16 +79,27 @@ err = consumer.StartConsuming(
if err != nil {
log.Fatal(err)
}
// block main thread so consumers run forever
forever := make(chan struct{})
<-forever
```
## 🚀 Quick Start Publisher
### Default options
```go
publisher, returns, err := rabbitmq.NewPublisher("amqp://user:pass@localhost")
if err != nil {
log.Fatal(err)
}
err = publisher.Publish([]byte("hello, world"), []string{"routing_key"})
if err != nil {
log.Fatal(err)
}
```
### With options
```go
publisher, returns, err := rabbitmq.GetPublisher(
publisher, returns, err := rabbitmq.NewPublisher(
"amqp://user:pass@localhost",
// can pass nothing for no logging
func(opts *rabbitmq.PublisherOptions) {


+ 2
- 2
consume.go View File

@ -25,8 +25,8 @@ type Delivery struct {
amqp.Delivery
}
// GetConsumer returns a new Consumer connected to the given rabbitmq server
func GetConsumer(url string, optionFuncs ...func(*ConsumerOptions)) (Consumer, error) {
// NewConsumer returns a new Consumer connected to the given rabbitmq server
func NewConsumer(url string, optionFuncs ...func(*ConsumerOptions)) (Consumer, error) {
options := &ConsumerOptions{}
for _, optionFunc := range optionFuncs {
optionFunc(options)


+ 1
- 1
examples/consumer/main.go View File

@ -7,7 +7,7 @@ import (
)
func main() {
consumer, err := rabbitmq.GetConsumer(
consumer, err := rabbitmq.NewConsumer(
"amqp://user:pass@localhost",
// can pass nothing for no logging
func(opts *rabbitmq.ConsumerOptions) {


+ 1
- 1
examples/publisher/main.go View File

@ -7,7 +7,7 @@ import (
)
func main() {
publisher, returns, err := rabbitmq.GetPublisher(
publisher, returns, err := rabbitmq.NewPublisher(
"amqp://user:pass@localhost",
// can pass nothing for no logging
func(opts *rabbitmq.PublisherOptions) {


+ 2
- 2
publish.go View File

@ -60,12 +60,12 @@ type PublisherOptions struct {
Logging bool
}
// GetPublisher returns a new publisher with an open channel to the cluster.
// NewPublisher returns a new publisher with an open channel to the cluster.
// If you plan to enforce mandatory or immediate publishing, those failures will be reported
// on the channel of Returns that you should setup a listener on.
// Flow controls are automatically handled as they are sent from the server, and publishing
// will fail with an error when the server is requesting a slowdown
func GetPublisher(url string, optionFuncs ...func(*PublisherOptions)) (Publisher, <-chan Return, error) {
func NewPublisher(url string, optionFuncs ...func(*PublisherOptions)) (Publisher, <-chan Return, error) {
options := &PublisherOptions{}
for _, optionFunc := range optionFuncs {
optionFunc(options)


Loading…
Cancel
Save