ActiveMQ command line: publish messages to a queue from a file?










2















I have an app that uses ActiveMQ, and typically, I test it by using AMQ's web UI to send messages to queues that my software is consuming from.



I'd like to semi-automate this and was hoping AMQ's command line has the capability to send a message to a specific queue by either providing that message as text in the command invocation, or ideally, reading it out of a file.



Examples:



./activemq-send queue="my-queue" messageFile="~/someMessage.xml"


or:



./activemq-send queue="my-queue" message="<someXml>...</someXml>"


Is there any way to do this?










share|improve this question


























    2















    I have an app that uses ActiveMQ, and typically, I test it by using AMQ's web UI to send messages to queues that my software is consuming from.



    I'd like to semi-automate this and was hoping AMQ's command line has the capability to send a message to a specific queue by either providing that message as text in the command invocation, or ideally, reading it out of a file.



    Examples:



    ./activemq-send queue="my-queue" messageFile="~/someMessage.xml"


    or:



    ./activemq-send queue="my-queue" message="<someXml>...</someXml>"


    Is there any way to do this?










    share|improve this question
























      2












      2








      2








      I have an app that uses ActiveMQ, and typically, I test it by using AMQ's web UI to send messages to queues that my software is consuming from.



      I'd like to semi-automate this and was hoping AMQ's command line has the capability to send a message to a specific queue by either providing that message as text in the command invocation, or ideally, reading it out of a file.



      Examples:



      ./activemq-send queue="my-queue" messageFile="~/someMessage.xml"


      or:



      ./activemq-send queue="my-queue" message="<someXml>...</someXml>"


      Is there any way to do this?










      share|improve this question














      I have an app that uses ActiveMQ, and typically, I test it by using AMQ's web UI to send messages to queues that my software is consuming from.



      I'd like to semi-automate this and was hoping AMQ's command line has the capability to send a message to a specific queue by either providing that message as text in the command invocation, or ideally, reading it out of a file.



      Examples:



      ./activemq-send queue="my-queue" messageFile="~/someMessage.xml"


      or:



      ./activemq-send queue="my-queue" message="<someXml>...</someXml>"


      Is there any way to do this?







      bash activemq






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 20:27









      hotmeatballsouphotmeatballsoup

      137312




      137312






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You could use the "A" utility to do this.



          a -b tcp://somebroker:61616 -p @someMessage.xml my-queue



          Disclaimer: I'm the author of A, wrote it once to do just this thing. There are other ways as well, such as the REST interface, a Groovy script and whatnot.






          share|improve this answer






























            2














            ActiveMQ has a REST interface that you can send messages to from the command line, using, for example, the curl utility.



            Here is a script I wrote and use for this very purpose:



            #!/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





            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308255%2factivemq-command-line-publish-messages-to-a-queue-from-a-file%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              You could use the "A" utility to do this.



              a -b tcp://somebroker:61616 -p @someMessage.xml my-queue



              Disclaimer: I'm the author of A, wrote it once to do just this thing. There are other ways as well, such as the REST interface, a Groovy script and whatnot.






              share|improve this answer



























                2














                You could use the "A" utility to do this.



                a -b tcp://somebroker:61616 -p @someMessage.xml my-queue



                Disclaimer: I'm the author of A, wrote it once to do just this thing. There are other ways as well, such as the REST interface, a Groovy script and whatnot.






                share|improve this answer

























                  2












                  2








                  2







                  You could use the "A" utility to do this.



                  a -b tcp://somebroker:61616 -p @someMessage.xml my-queue



                  Disclaimer: I'm the author of A, wrote it once to do just this thing. There are other ways as well, such as the REST interface, a Groovy script and whatnot.






                  share|improve this answer













                  You could use the "A" utility to do this.



                  a -b tcp://somebroker:61616 -p @someMessage.xml my-queue



                  Disclaimer: I'm the author of A, wrote it once to do just this thing. There are other ways as well, such as the REST interface, a Groovy script and whatnot.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 13:07









                  Petter NordlanderPetter Nordlander

                  19.3k43776




                  19.3k43776























                      2














                      ActiveMQ has a REST interface that you can send messages to from the command line, using, for example, the curl utility.



                      Here is a script I wrote and use for this very purpose:



                      #!/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





                      share|improve this answer



























                        2














                        ActiveMQ has a REST interface that you can send messages to from the command line, using, for example, the curl utility.



                        Here is a script I wrote and use for this very purpose:



                        #!/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





                        share|improve this answer

























                          2












                          2








                          2







                          ActiveMQ has a REST interface that you can send messages to from the command line, using, for example, the curl utility.



                          Here is a script I wrote and use for this very purpose:



                          #!/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





                          share|improve this answer













                          ActiveMQ has a REST interface that you can send messages to from the command line, using, for example, the curl utility.



                          Here is a script I wrote and use for this very purpose:



                          #!/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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 15 '18 at 23:47









                          Rob NewtonRob Newton

                          404410




                          404410



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308255%2factivemq-command-line-publish-messages-to-a-queue-from-a-file%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo