I'm passing messages to my Azure service bus queue like this, where the 'MessageId' value is a string of a number ex. '345'. I see it in the queue in my Azure portal dashboard and when I look at the message in Service Bus Explorer I see the message id as the eventId I'm passing it.
Message message = new Message
{
MessageId = eventId.ToString(), // passing it a value of '123'
ScheduledEnqueueTimeUtc = enqueuedTime
};
var sendCodeSequence = await queueClient.ScheduleMessageAsync(message, new DateTimeOffset(enqueuedTime));
But when my function gets triggered I'm getting an exception saying the myQueueItem
from the function is either 0
or null
, depending on which function I'm calling.
Here is the first couple of lines of code for one of the functions that are giving me this problem. The event is always null and throws an exception because myQueueItem
is always null
or 0
.
I had this working before, I thought, but now I think changes were made and throwing exceptions each time my functions get triggered!
Question - Is myQueueItem
not the messageId I'm passing it when I create and put the message on the queue?
[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);