Apache Camel Azure 队列:发送消息时消息正文为空
Posted
技术标签:
【中文标题】Apache Camel Azure 队列:发送消息时消息正文为空【英文标题】:Apache Camel Azure queue: Message body is empty while sending message 【发布时间】:2021-01-30 09:10:28 【问题描述】:我正在尝试使用 Apache Camel 向 Azure 队列发送消息,路由代码为:
from("direct:testMessage")
.process(exchange ->
exchange.getIn().setBody("test message");
)
.to("azure-storage-queue://azureaccount/test-queue?operation=sendMessage");
启动 Azure 服务客户端 bean 的代码是:
@Bean
public QueueServiceClient queueServiceClient()
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(ACCOUNT, ACCESS_KEY);
return new QueueServiceClientBuilder().endpoint(QUEUE_URL).credential(credential).buildClient();
我收到以下错误:
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>"
尝试启用 HTTP 日志,但消息正文似乎为空:
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】:浏览camel-azure组件的源码,发现正确的消息发送方式如下:
exchange.getIn().getHeaders().put(QueueConstants.MESSAGE_TEXT, "test message");
【讨论】:
以上是关于Apache Camel Azure 队列:发送消息时消息正文为空的主要内容,如果未能解决你的问题,请参考以下文章
文件目录无法从 apache camel 上传 azure blob 上的文件