I am trying to receive Azure Queue Message from Java. I am able to receive message using BrokeredMessage in java. (I am novice to java).
My problem is message.getBody() is returning some header information as well (Not just the message as I need).
I get string3http://schemas.mi@string3http://schemas.microsoft.com/2003/10/Serialization/?? message appended with my body in front of it. How can I get rid of this header information.
And I also I noticed i get message in two batches. (Not the whole lot at once)
My first batch of message.getBody()returns below message
'@string3http://schemas.mi'
My Second batch of message.getBody()returns below message
@crosoft.com/2003/10/Serialization/?? + My actual message.
MY total message size is less than 500B, But I have set byte size to 4096. So is is not splinting because of size issue.
This is my receiver code I use.
ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
opts.setReceiveMode(ReceiveMode.PEEK_LOCK);
while (true)
{
ReceiveQueueMessageResult resultQM =
service.receiveQueueMessage("MyqueueName", opts);
BrokeredMessage message = resultQM.getValue();
if (message != null && message.getMessageId() != null)
{
byte[] b = new byte[4096];
String s = null;
int numRead = message.getBody().read(b);
while (-1 != numRead)
{
s = new String(b);
s = s.trim();
System.out.print(s);
numRead = message.getBody().read(b);
}
}
}
This is the total output of System.out.print(s);. (But in two batches as I mentioned before)
total output
string3http://schemas.microsoft.com/2003/10/Serialization/??+ My actual message.
Any Help is much appreciated!
I think you are getting the above sample from here. Before proceeding with the Code, we need to understand about Receive Mode Lock types which are
PeekLock
andReceiveAndDelete
ReceiveAndDelete:
PeekLook:
You are trying with the PeekLock Mode, in which you need to explicitly call the
deleteMessage(message)
in order to mark the message as being consumed unless you didn't call this method, even though it looks like consumed, but it not actually consumed. It still in the Queue.I think the header which you are mentioning is not the actual header, it was the initial message in the queue, which is actually not consumed at all
You can check this like change your code like the below and try