我正在尝试使用 AMQP 0.9.1 Go 客户端连接到 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>
查看示例代码,客户端似乎是这个“github.com/streadway/amqp”,它来自“https://github.com/streadway/amqp”,它似乎是一个已失效的分支RabbitMQ AMQP 0.9.1 客户端。
由于 Artemis 代理是 AMQP 1.0 代理,因此来自不受支持的协议客户端版本的连接尝试触发令人困惑的错误也就不足为奇了。我的第一个建议是切换到 AMQP 1.0 客户端,因为这将是最直接需要修复的事情,然后您可以从那里开始解决任何其他错误。
谢谢您的回答。我正在分享有关我的经纪人文件的更多详细信息。也许您对客户有不同的建议。
<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>
客户端代码必须带有GO。再次感谢您。