无法使用AMQP 0.9.1 Go客户端连接ActiveMQ Artemis
使用AMQP 0.9.1 Go客户端连接ActiveMQ Artemis遇到的问题
我尝试用AMQP 0.9.1的Go客户端连接ActiveMQ Artemis代理,但遇到了无法解决的问题。我的broker.xml里未配置SSL,却出现了SSL证书相关错误;用STOMP协议通过Dial()方法能正常连接,但AMQP协议无法正常工作。
AMQP客户端代码
package main import ( "fmt" "log" "github.com/streadway/amqp" ) func main() { brokerURL := "amqp://admin:admin@10.37.129.2:61616" // 更新为你的代理URL queueName := "amqp/message" // 使用自定义TLS配置创建AMQP连接 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, // 队列名称 false, // 是否持久化 false, // 未使用时是否删除 false, // 是否排他 false, // 是否非阻塞 nil, // 参数 ) if err != nil { log.Fatalf("Failed to declare a queue: %v", err) } body := "Hello, Artemis AMQP!" err = ch.Publish( "", // 交换器 q.Name, // 路由键 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.") }
正常工作的STOMP连接代码
conn, err = stomp.Dial("tcp", addr, stomp.ConnOpt.Login(username, password))
错误信息
客户端运行错误
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
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>
内容的提问来源于stack exchange,提问作者user6244
相关产品推荐
相关产品推荐

