Browse Source

queue, exchange and binding declaration is now simplified and much clearer to use

pull/81/head
Christoph Haas 3 years ago
parent
commit
70a7350572
2 changed files with 33 additions and 9 deletions
  1. +32
    -8
      README.md
  2. +1
    -1
      declare.go

+ 32
- 8
README.md View File

@ -10,7 +10,7 @@ Supported by [Boot.dev](https://boot.dev)
[Streadway's AMQP](https://github.com/rabbitmq/amqp091-go) library is currently the most robust and well-supported Go client I'm aware of. It's a fantastic option and I recommend starting there and seeing if it fulfills your needs. Their project has made an effort to stay within the scope of the AMQP protocol, as such, no reconnection logic and few ease-of-use abstractions are provided. [Streadway's AMQP](https://github.com/rabbitmq/amqp091-go) library is currently the most robust and well-supported Go client I'm aware of. It's a fantastic option and I recommend starting there and seeing if it fulfills your needs. Their project has made an effort to stay within the scope of the AMQP protocol, as such, no reconnection logic and few ease-of-use abstractions are provided.
### Goal
### Goal
The goal with `go-rabbitmq` is to still provide most all of the nitty-gritty functionality of AMQP, but to make it easier to work with via a higher-level API. Particularly: The goal with `go-rabbitmq` is to still provide most all of the nitty-gritty functionality of AMQP, but to make it easier to work with via a higher-level API. Particularly:
@ -48,7 +48,6 @@ err = consumer.StartConsuming(
return rabbitmq.Ack return rabbitmq.Ack
}, },
"my_queue", "my_queue",
[]string{"routing_key1", "routing_key2"}
) )
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -74,13 +73,7 @@ err = consumer.StartConsuming(
return rabbitmq.Ack return rabbitmq.Ack
}, },
"my_queue", "my_queue",
[]string{"routing_key", "routing_key_2"},
rabbitmq.WithConsumeOptionsConcurrency(10), rabbitmq.WithConsumeOptionsConcurrency(10),
rabbitmq.WithConsumeOptionsQueueDurable,
rabbitmq.WithConsumeOptionsQuorum,
rabbitmq.WithConsumeOptionsBindingExchangeName("events"),
rabbitmq.WithConsumeOptionsBindingExchangeKind("topic"),
rabbitmq.WithConsumeOptionsBindingExchangeDurable,
rabbitmq.WithConsumeOptionsConsumerName(consumerName), rabbitmq.WithConsumeOptionsConsumerName(consumerName),
) )
if err != nil { if err != nil {
@ -137,6 +130,37 @@ go func() {
}() }()
``` ```
## 🚀 Quick Start Queue, Exchange and Binding Declaration
### Consumer
```go
consumer, err := rabbitmq.NewConsumer("amqp://user:pass@localhost", rabbitmq.Config{})
if err != nil {
log.Fatal(err)
}
defer consumer.Close()
err = consumer.StartConsuming(
func(d rabbitmq.Delivery) rabbitmq.Action {
log.Printf("consumed: %v", string(d.Body))
// rabbitmq.Ack, rabbitmq.NackDiscard, rabbitmq.NackRequeue
return rabbitmq.Ack
},
"my_queue",
rabbitmq.WithConsumeDeclareOptions(
rabbitmq.WithDeclareQueueDurable,
rabbitmq.WithDeclareQueueQuorum,
rabbitmq.WithDeclareExchangeName("events"),
rabbitmq.WithDeclareExchangeKind("topic"),
rabbitmq.WithDeclareExchangeDurable,
rabbitmq.WithDeclareBindingsForRoutingKeys([]string{"routing_key", "routing_key_2"}),
),
)
if err != nil {
log.Fatal(err)
}
```
## Other usage examples ## Other usage examples
See the [examples](examples) directory for more ideas. See the [examples](examples) directory for more ideas.


+ 1
- 1
declare.go View File

@ -354,7 +354,7 @@ func WithDeclareExchangeNoDeclare(options *DeclareOptions) {
// WithDeclareBindingNoWait sets the bindings to nowait, which means if the queue can not be bound // WithDeclareBindingNoWait sets the bindings to nowait, which means if the queue can not be bound
// the channel will not be closed with an error. // the channel will not be closed with an error.
// This function must be called after bindings have been defined, otherwise it has no effect. // This function must be called after bindings have been defined, otherwise it has no effect.
func WithDeclareBindingNoWait(options *ConsumeOptions) {
func WithDeclareBindingNoWait(options *DeclareOptions) {
for i := range options.Bindings { for i := range options.Bindings {
options.Bindings[i].NoWait = true options.Bindings[i].NoWait = true
} }


Loading…
Cancel
Save