Apache Camel Azure queue: Message body is empty while sending message

247 views Asked by At

I am trying to send a message to Azure Queue using Apache Camel, route code is:

from("direct:testMessage")
    .process(exchange -> {
        exchange.getIn().setBody("test message");
    })
    .to("azure-storage-queue://azureaccount/test-queue?operation=sendMessage");

The code to initiate Azure service client bean is:

@Bean
public QueueServiceClient queueServiceClient() {
    StorageSharedKeyCredential credential = new StorageSharedKeyCredential(ACCOUNT, ACCESS_KEY);
    return new QueueServiceClientBuilder().endpoint(QUEUE_URL).credential(credential).buildClient();
}

I am getting the below error:

com.azure.storage.queue.models.QueueStorageException: Status code 400, "<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidXmlDocument</Code><Message>XML specified is not syntactically valid.
RequestId:e3496af3-f003-001a-0d2e-a38636000000
Time:2020-10-15T20:08:26.5431469Z</Message><LineNumber>0</LineNumber><LinePosition>0</LinePosition><Reason /></Error>"
    

Tried enabling HTTP logs and looks like the Message body is empty:

2020-10-16 01:38:25 INFO  c.a.s.q.i.M.enqueue - --> POST https://azureaccount.queue.core.windows.net/blob-backup-queue/messages
53-byte body:
<?xml version='1.0' encoding='UTF-8'?><QueueMessage/>
--> END POST

2020-10-16 01:38:25 INFO  c.a.s.q.i.M.enqueue - <-- 400 https://azureaccount.queue.core.windows.net/blob-backup-queue/messages (163 ms, 294-byte body)
Response body:
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidXmlDocument</Code><Message>XML specified is not syntactically valid.
RequestId:e3496af3-f003-001a-0d2e-a38636000000
Time:2020-10-15T20:08:26.5431469Z</Message><LineNumber>0</LineNumber><LinePosition>0</LinePosition><Reason /></Error>
<-- END HTTP
1

There are 1 answers

0
Saud On

Going through the source code of camel-azure component, figured out the right way to send message is as follows:

exchange.getIn().getHeaders().put(QueueConstants.MESSAGE_TEXT, "test message");