我有一个使用ActiveMQ的应用程序,通常,我通过使用AMQ的Web UI将消息发送到我的软件正在使用的队列来测试它。
我想半自动化,并希望AMQ的……
ActiveMQ有一个REST接口,您可以使用,例如,从命令行发送消息 curl 效用。
curl
这是我为此目的编写并使用的脚本:
#!/bin/bash # # # Sends a message to the message broker on localhost. # Uses ActiveMQ's REST API and the curl utility. # if [ $# -lt 2 -o $# -gt 3 ] ; then echo "Usage: msgSender (topic|queue) DESTINATION [ FILE ]" echo " Ex: msgSender topic myTopic msg.json" echo " Ex: msgSender topic myTopic <<< 'this is my message'" exit 2 fi UNAME=admin PSWD=admin TYPE=$1 DESTINATION=$2 FILE=$3 BHOST=${BROKER_HOST:-'localhost'} BPORT=${BROKER_REST_PORT:-'8161'} if [ -z "$FILE" -o "$FILE" = "-" ] ; then # Get msg from stdin if no filename given ( echo -n "body=" ; cat ) \ | curl -u $UNAME:$PSWD --data-binary '@-' --proxy "" \ "http://$BHOST:$BPORT/api/message/$DESTINATION?type=$TYPE" else # Get msg from a file if [ ! -r "$FILE" ] ; then echo "File not found or not readable" exit 2 fi ( echo -n "body=" ; cat $FILE ) \ | curl -u $UNAME:$PSWD --data-binary '@-' --proxy "" \ "http://$BHOST:$BPORT/api/message/$DESTINATION?type=$TYPE" fi
你可以使用 “A”实用程序 去做这个。
a -b tcp://somebroker:61616 -p?@someMessage.xml my-queue
免责声明:我是A的作者,曾写过一次这样的事情。还有其他方法,例如REST接口,Groovy脚本等等。