有没有办法在将消息ID插入队列Azure后获取消息ID?
CloudStorageAccount storageAccount =
CloudStorageAccount.parse(storageConnectionString);
CloudQueueClient queueClient = storageAccount.createCloudQueueClient();
CloudQueue queue = queueClient.getQueueReference("myqueue");
queue.createIfNotExist();
CloudQueueMessage message = new CloudQueueMessage("Hello, World");
queue.addMessage(message);
// Get message ID here ?
答案 0 :(得分:3)
只有这样您才能获得消息ID by getting the message
。因此,您必须使用GetMessage
或GetMessages
方法从队列中获取消息。但是,由于GetMessages
只能从队列顶部返回最多32条可见消息,因此无法保证您将获得刚刚创建的消息。
答案 1 :(得分:0)
由于队列的原则是“先入先出”或FIFO,这就是为什么你不能随时获得特定的消息,但你必须使用GetMessage并迭代它。
答案 2 :(得分:0)
I realize it has been 5 years since this was originally asked; however, it is now possible to achieve this.
CloudQueueMessage message = new CloudQueueMessage("Hello, World");
queue.AddMessage(message);
// here's how you get the id
string id = message.Id;