[英]Is it possible to output Message/BrokeredMessage with Azure Functions V2?
It isn't clear from the docs how to output a structured message. 从文档尚不清楚如何输出结构化消息。 In an old function I've used
BrokeredMessage
, and the docs say to use Message
for V2 functions, however there is no guidance on how to use this. 在一个旧函数中,我使用了
BrokeredMessage
,文档中说将Message
用于V2函数,但是没有关于如何使用它的指南。 Is this correct: 这个对吗:
[FunctionName(nameof(Job))]
public static async Task<IActionResult> Job(
// ...
IAsyncCollector<Microsoft.Azure.ServiceBus.Message> serializedJobCollector
)
The goal is to be able to set some metadata properties like the ID, which I've done before (with V1 and BrokeredMessage
) for duplicate detection, but I'm not sure if this is correct or I need to serialize to a string or what... 我们的目标是能够设置一些元数据属性,例如ID(我之前已经使用V1和
BrokeredMessage
)以进行重复检测,但是我不确定这是否正确,或者我需要序列化为字符串还是什么...
You have found the right way, as the doc says 正如文档所说,您已经找到了正确的方法
for 2.x, use Message instead of BrokeredMessage
对于2.x,使用Message而不是BrokeredMessage
To take an example 举个例子
[FunctionName("FunctionTest")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[ServiceBus(queueOrTopicName:"queueName",Connection ="ServiceBusConnection")]IAsyncCollector<Message> outputMessages,
ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var message = new Message
{
Body = System.Text.Encoding.UTF8.GetBytes(requestBody),
MessageId = "MyMessageId"
};
await outputMessages.AddAsync(message);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.