0
votes

I am trying to send message to ActiveMQ server with my client app written on C# .NET. I have XML messages which I have converted into Zip stream and trying to send.

public IMessage SendMessage(string mqUri, string brokerUri, MemoryStream message, string username, string password)
    {
        Uri connecturi = new Uri(mqUri);

        IConnectionFactory factory = new NMSConnectionFactory(connecturi);

        using (IConnection connection = factory.CreateConnection(username, password))
        using (ISession session = connection.CreateSession())
        {
            IDestination destination = SessionUtil.GetDestination(session, brokerUri);

            using (IMessageProducer producer = session.CreateProducer(destination))
            {
                connection.Start();
                IBytesMessage request = session.CreateBytesMessage(message.ToArray());
                producer.Send(request);

                return request;
            }
        }
    }

On server side when parsing data got exception like:

Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - Failed to extract body due to: javax.jms.JMSException: Failed to build body from bytes. Reason: java.io.StreamCorruptedException: invalid stream header: 00010000. Message: ActiveMQObjectMessage.

When I debug the code and set break point, there is exception on Bodylength and content saying 'request.Content' threw an exception of type 'Apache.NMS.MessageNotReadableException'

enter image description here

Is there any special zip conversion to send message on ActiveMQ server? Please Help. Thanks

1
why converting an xml to zip ?? can you open the zip file with any zip tools ?Hassen Bennour

1 Answers

0
votes

The problem was converting zip to memorystream, Later I found it needs to convert .xml file to zipstream not the zip file.

public static MemoryStream CreateZipStream()
    {
        using (ZipFile zip = new ZipFile())
        {
            MemoryStream outputStream = new MemoryStream();
            outputStream.Seek(0, SeekOrigin.Begin);
            string filePath =
                @"C:\YourXml.xml";
            zip.AddFile(filePath);
            zip.Save(outputStream);
            return outputStream;
        }
    }