我的Azure函数中的“ myQueueItem”在被触发时会产生一个零值

时间:2018-08-26 02:58:19

标签: c# azure azure-functions azureservicebus azure-triggers

我正在像这样将消息传递到我的Azure服务总线队列,其中“ MessageId”值是数字ex的字符串。 '345'。我在Azure门户仪表板的队列中看到它,当我在Service Bus Explorer中查看消息时,我看到消息ID为我正在传递的eventId。

 Message message = new Message
 {
     MessageId = eventId.ToString(), // passing it a value of '123'
     ScheduledEnqueueTimeUtc = enqueuedTime
 };

 var sendCodeSequence = await queueClient.ScheduleMessageAsync(message, new DateTimeOffset(enqueuedTime));

但是当我的函数被触发时,我收到一个异常,说该函数中的myQueueItem 0null ,具体取决于哪个函数我在打电话。

这是给我这个问题的一个函数的前两行代码。该事件始终为null并引发异常,因为myQueueItem始终为 null0

我以前曾经做过这项工作,但现在我认为每次我的函数被触发时都会进行更改并引发异常!

问题-创建我的消息并将其放入队列时,myQueueItem是否不是我要传递的messageId?

[FunctionName("CancelEvent")]
    public static void Run([ServiceBusTrigger("canceleventqueue", AccessRights.Manage, Connection = "events2017_RootManageSharedAccessKey_SERVICEBUS")]string myQueueItem, TraceWriter log, ExecutionContext context)
    {
        try
        {
            log.Info($"Cancel event started id: {myQueueItem}");

            var eventId = Convert.ToInt32(myQueueItem);

            using (var dbContext = new EventContext(myDatabaseConnectionString))
            {
                var event = dbContext.Events.Where(i => i.EventId == eventId).FirstOrDefault();

                if (Event == null)
                    throw new Exception("no event with this id: " + myQueueItem);

2 个答案:

答案 0 :(得分:0)

myQueueItem是消息本身。如果您已使用代理消息或服务总线消息并添加了要在函数中使用的其他信息,则字符串myQueueItem并不是真正有用的。您应将string myQueueItem替换为Microsoft.Azure.ServiceBus.Message myQueueItem。如果需要,还可以查看本文中的实现以获取有关对消息进行序列化/反序列化的其他有用信息:Azure ServiceBus Message Serialization/Deserialization

答案 1 :(得分:0)

我通过在函数中传入'string messageId'作为参数来解决它。我猜Azure消息的使用方式不同于BrokeredMessages。

相关问题