Skip to content

Commit

Permalink
Merge pull request #1 from godaner/dev
Browse files Browse the repository at this point in the history
fix amqp bind default exchange failure
  • Loading branch information
godaner authored Feb 25, 2021
2 parents f1e46e5 + 4ec7e8b commit 3c853ea
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Or get it from the released version:

https://github.com/godaner/brokerc/releases

> Note: curl -LJO https://github.com/godaner/brokerc/releases/download/v1.0.1/brokerc_linux-amd64.tar.gz, tar -zxvf brokerc_linux-amd64.tar.gz
> Note: curl -LJO https://github.com/godaner/brokerc/releases/download/v1.0.2/brokerc_linux-amd64.tar.gz, tar -zxvf brokerc_linux-amd64.tar.gz
# Supported platforms

Expand Down Expand Up @@ -60,7 +60,7 @@ USAGE:
brokerc [global options] command [command options] [arguments...]
VERSION:
v1.0.1
v1.0.2
COMMANDS:
mqttpub publish mqtt message
Expand Down
18 changes: 10 additions & 8 deletions broker/amqpv1/amqpv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,19 @@ func (s *amqpSubscriber) subscribe() (err error) {
if err != nil {
return err
}
if len(topics) == 0 {
err = s.ch.QueueBind(q.Name, "", s.opts.ExchangeName, false, nil)
if err != nil {
return err
}
} else {
for _, topic := range topics {
err = s.ch.QueueBind(q.Name, topic, s.opts.ExchangeName, false, nil)
if s.opts.ExchangeName != "" {
if len(topics) == 0 {
err = s.ch.QueueBind(q.Name, "", s.opts.ExchangeName, false, nil)
if err != nil {
return err
}
} else {
for _, topic := range topics {
err = s.ch.QueueBind(q.Name, topic, s.opts.ExchangeName, false, nil)
if err != nil {
return err
}
}
}
}
msgs, err := s.ch.Consume(
Expand Down
28 changes: 28 additions & 0 deletions broker/amqpv1/amqpv1_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package amqpv1

import (
"fmt"
"github.com/godaner/brokerc/broker"
"github.com/godaner/brokerc/log/logv1"
"os"
"testing"
)

func TestAMQPBrokerV1_Connect(t *testing.T) {
a := &AMQPBrokerV1{
URI: "amqp://system:[email protected]:5672/",
CID: "test1",
Logger: &logv1.LoggerV1{
DebugWriter: os.Stdout,
InfoWriter: os.Stdout,
WarnWriter: os.Stdout,
ErrorWriter: os.Stdout,
},
}
a.Connect()
defer a.Disconnect()
fmt.Println(a.Subscribe([]string{"test1"}, func(event broker.Event) error {
fmt.Println(event)
return nil
}, broker.SetSubQueue("testqueue1")))
}
2 changes: 1 addition & 1 deletion brokerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
app.Name = "brokerc"
app.HelpName = "brokerc"
app.Usage = "brokerc is a cross-platform publish and subscribe command line client tool, including mqtt client, amqp client, kafka client, http client."
app.Version = "v1.0.1"
app.Version = "v1.0.2"
app.Commands = []cli.Command{
MQTTPublishCommand,
MQTTSubscribeCommand,
Expand Down

0 comments on commit 3c853ea

Please sign in to comment.