我试图用AMQP 0.9.1 Go client连接到ActiveMQ Artemis代理,但有一些问题我无法解决。
这是我的客户代码:
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.")
}
在我的broker.xml
没有SSL证书,但我得到SSL证书错误.使用STOMP,我可以用Dial()
连接到ActiveMQ 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配置。
下面是我的broker.xml
:
<connectors>
<connector name="artemis">tcp://10.37.129.2:61616</connector>
</connectors>
<acceptors>
<acceptor name="artemis">tcp://10.37.129.2:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;supportAdvisory=false;suppressInternalManagementObjects=false</acceptor>
</acceptors>
<cluster-user>admin</cluster-user>
<cluster-password>admin</cluster-password>
<!-- Clustering configuration -->
<broadcast-groups>
<broadcast-group name="bg-group1">
<group-address>${udp-address:231.7.7.7}</group-address>
<group-port>9876</group-port>
<broadcast-period>100</broadcast-period>
<connector-ref>artemis</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="dg-group1">
<group-address>${udp-address:231.7.7.7}</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>artemis</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>ON_DEMAND</message-load-balancing>
<max-hops>1</max-hops>
<static-connectors>
<connector-ref>artemis</connector-ref>
</static-connectors>
</cluster-connection>
</cluster-connections>
<ha-policy>
<replication>
<master>
<!-- Configure other replication settings as needed -->
<check-for-live-server>true</check-for-live-server>
</master>
</replication>
</ha-policy>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="amq"/>
<permission type="deleteNonDurableQueue" roles="amq"/>
<permission type="createDurableQueue" roles="amq"/>
<permission type="deleteDurableQueue" roles="amq"/>
<permission type="createAddress" roles="amq"/>
<permission type="deleteAddress" roles="amq"/>
<permission type="consume" roles="amq"/>
<permission type="browse" roles="amq"/>
<permission type="send" roles="amq"/>
<!-- we need this otherwise ./artemis data imp wouldn't work -->
<permission type="manage" roles="amq"/>
</security-setting>
</security-settings>
1条答案
按热度按时间ugmeyewa1#
查看示例代码,客户端似乎是这个“github.com/streadway/amqp”,它来自这里“https://github.com/streadway/amqp”,它似乎是RabbitMQ AMQP 0.9.1客户端的一个已失效的分支。
由于Artemis代理是一个AMQP 1.0代理,因此,来自不支持的协议客户端版本的连接尝试触发令人困惑的错误也就不足为奇了。然后我的第一个建议是切换到AMQP 1.0客户端,因为这将是最直接的事情来修复,然后您可以从那里工作来解决任何额外的错误。