我正在尝试将 Artemis 代理与 amqp 客户端连接。但有一些问题我无法解决。
这是我的客户代码:
package main
import (
"fmt"
"log"
"github.com/streadway/amqp"
)
func main() {
brokerURL := "amqp://admin:[email protected]:61616" // Update with your broker URL
queueName := "amqp/message"
// Create an AMQP connection with the custom TLS configuration
conn, err := amqp.Dial(brokerURL)
if err != nil {
log.Fatalf("Failed to connect to: %v", err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
log.Fatalf("Failed to open a channel: %v", err)
}
defer ch.Close()
q, err := ch.QueueDeclare(
queueName, // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
log.Fatalf("Failed to declare a queue: %v", err)
}
body := "Hello, Artemis AMQP!"
err = ch.Publish(
"", // exchange
q.Name, // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/plain",
Body: []byte(body),
})
if err != nil {
log.Fatalf("Failed to publish a message: %v", err)
}
fmt.Println("Message sent successfully.")
}
我的经纪人没有 ssl 配置,但我收到 sll 证书错误。使用 STOMP,我可以使用 Dial() 连接到 artemis,但 AMQP 不起作用。
conn, err = stomp.Dial("tcp", addr, stomp.ConnOpt.Login(username, password))
当我运行 amqp 客户端代码时,我收到此错误
Failed to connect to: Exception (501) Reason: "Exception (501) Reason: \"frame could not be parsed\""
exit status 1
在服务器端我收到以下错误:
832 WARN [org.apache.activemq.artemis.core.server] AMQ222216: Security problem while authenticating: AMQ229031: Unable to validate user from null. Username: null; SSL certificate subject DN: unavailable
我想连接到服务器而不需要 SSL 配置。
查看示例代码,客户端似乎是这个“github.com/streadway/amqp”,它来自“https://github.com/streadway/amqp”,它似乎是一个已失效的分支RabbitMQ AMQP 0.9.1 客户端。
由于 Artemis 代理是 AMQP 1.0 代理,因此来自支持的协议客户端的连接尝试触发令人困惑的错误也就不足为奇了。我的第一个建议是切换到 AMQP 1.0 客户端,因为这将是最直接需要修复的事情,然后您可以从那里开始解决任何其他错误。