Skip to content

Commit

Permalink
Add vhost support to AMQP
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuratczyk committed Feb 20, 2024
1 parent 9e6b513 commit 64a6f4f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func defaultUri(proto string) string {
uri := "localhost"
switch proto {
case "amqp":
uri = "amqp://localhost"
uri = "amqp://localhost/"
case "stomp":
uri = "localhost:61613"
case "mqtt":
Expand Down
4 changes: 3 additions & 1 deletion pkg/amqp10_client/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ type Amqp10Consumer struct {

func NewConsumer(cfg config.Config, id int) *Amqp10Consumer {
// open connection
conn, err := amqp.Dial(context.TODO(), cfg.ConsumerUri, nil)
conn, err := amqp.Dial(context.TODO(), cfg.ConsumerUri, &amqp.ConnOptions{
HostName: amqpVHost(cfg.ConsumerUri),

Check failure on line 32 in pkg/amqp10_client/consumer.go

View workflow job for this annotation

GitHub Actions / Build and test

undefined: amqpVHost
})
if err != nil {
log.Error("consumer failed to connect", "protocol", "amqp-1.0", "consumerId", id, "error", err.Error())
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/amqp10_client/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type Amqp10Publisher struct {

func NewPublisher(cfg config.Config, n int) *Amqp10Publisher {
// open connection
conn, err := amqp.Dial(context.TODO(), cfg.PublisherUri, nil)
conn, err := amqp.Dial(context.TODO(), cfg.PublisherUri, &amqp.ConnOptions{
HostName: amqpVHost(cfg.PublisherUri)})

Check failure on line 32 in pkg/amqp10_client/publisher.go

View workflow job for this annotation

GitHub Actions / Build and test

undefined: amqpVHost
if err != nil {
log.Error("publisher connection failed", "protocol", "amqp-1.0", "publisherId", n, "error", err.Error())
return nil
Expand Down

1 comment on commit 64a6f4f

@chadknutson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks TLS support for the AMQP 1.0 client. When you override the Hostname parameter in the amqp.Dial method, the TLS path now expects the host's certificate to match something of the form "vhost:[specified vhost]". That simply won't work.

Here is the error when running with a urlstring that specifies 'amqps':
level=ERROR msg="consumer failed to connect" protocol=amqp-1.0 consumerId=1 hostname=vhost:/ error="tls: failed to verify certificate: x509: certificate is valid for [my host name here], not vhost:/"

Please sign in to comment.