Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using this package to connect to QPID #31

Closed
lg007 opened this issue May 7, 2021 · 2 comments
Closed

Using this package to connect to QPID #31

lg007 opened this issue May 7, 2021 · 2 comments

Comments

@lg007
Copy link

lg007 commented May 7, 2021

Hello,

I am trying to use this package to connect to a QPID AMQP broker (it implements AMQP 1.0) and to send some messages. I am using the sample code that can be found on the godoc page, but I get the following error after connection:

2021/05/07 17:40:17 Creating sender link:*Error{Condition: amqp:invalid-field, Description: received Attach with remote null terminus., Info: map[]}
exit status 1

Here is my code:

package main

import (
	"context"
	"fmt"
	"github.com/Azure/go-amqp"
	"log"
	"time"
)

func main() {

	// Create client
	client, err := amqp.Dial("amqp://sptest.aaaa.bb",
		amqp.ConnSASLPlain("abababa", "cdcdcdc"),
	)
	fmt.Println("dial ok")
	if err != nil {
		log.Fatal("Dialing AMQP server:", err)
	}
	defer client.Close()

	// Open a session
	session, err := client.NewSession()
	if err != nil {
		log.Fatal("Creating AMQP session:", err)
	}
	fmt.Println("session opened")

	ctx := context.Background()

	// Send a message
	{
		// Create a sender
		sender, err := session.NewSender(
			amqp.LinkTargetAddress("/myTestQueue"),
//			amqp.LinkTargetTimeout(10),
//			amqp.LinkTargetDurability(2),
		)
		if err != nil {
			log.Fatal("Creating sender link:", err)
		}
		fmt.Println("Sender link created")

		ctx, cancel := context.WithTimeout(ctx, 5*time.Second)

		// Send message
		err = sender.Send(ctx, amqp.NewMessage([]byte("Hello!")))
		if err != nil {
			log.Fatal("Sending message:", err)
		}

		sender.Close(ctx)
		cancel()
	}
}

I have tried many different ways to enter the queue name, with slash, without it, with TargetDurability, etc,. but no luck. Dialing is OK, session is opened, but then it exits with error.

From the same machine, using the same connection credentials, I can easily connect and send using node.js with rhea. This means that the problem must be in my code. I am sure I am missing some obvious thing, probably on how to reference the queue.

Any help is appreciated.

@kukumber
Copy link

Java qpid waits for source and target addresses simultaneously (see https://issues.apache.org/jira/browse/QPID-7981). So, as a workaround you have to send both of them (source might be an empty string):

sender, err := session.NewSender(
    amqp.LinkTargetAddress("/myTestQueue"),
    amqp.LinkSourceAddress(""),
)

@lg007
Copy link
Author

lg007 commented May 18, 2021

Thanks a lot for your answer, indeed this is the solution to the problem.

Perhaps one more comment if anyone reading this needs some more advice: the slash at the beginning of the queue name is not needed, the code only works if it is not included (at least in my setup).

@lg007 lg007 closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants