Search code examples
activemq-artemisproducer

ActiveMQ Artemis producer can't send a file


If I run from command line (Windows):

artemis producer --message-count 1 --user xxx --password yyy --data /path/to/file

I get this error:

Error occurred during import.  Rolling back.
java.util.NoSuchElementException: END_DOCUMENT reached: no more elements on the stream.
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:593)
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.nextTag(XMLStreamReaderImpl.java:1346)
        at org.apache.activemq.artemis.cli.factory.serialize.XMLMessageSerializer.read(XMLMessageSerializer.java:52)
        at org.apache.activemq.artemis.cli.commands.messages.Producer.execute(Producer.java:175)
        at org.apache.activemq.artemis.cli.Artemis.internalExecute(Artemis.java:212)
        at org.apache.activemq.artemis.cli.Artemis.execute(Artemis.java:162)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at org.apache.activemq.artemis.boot.Artemis.execute(Artemis.java:144)
        at org.apache.activemq.artemis.boot.Artemis.main(Artemis.java:61)

With --message I have no problem


Solution

  • Using --data doesn't send the specified file as an individual message. It reads the data in the file and potentially serializes it into multiple messages. However, in order to serialize the messages from the specified file you either need to provide your own implementation of org.apache.activemq.artemis.cli.factory.serialize.MessageSerializer (via the --serializer option) or use the default XML-based implementation (i.e. org.apache.activemq.artemis.cli.factory.serialize.XMLMessageSerializer) which uses a format like this:

    <messages>
       <message type="text">
          <body>
             <![CDATA[MESSAGE HERE]]>
          </body>
       </message>
    </messages>
    

    You are receiving an error because you're using the default XML-based serializer but your file is not the right format.