0

I'm adding a message to my Azure service bus queue and returning its Guid to save in a db, but for some reason I either modified something or it never worked correctly in the first place. Question - can I have multiple message id's with the same id the different queues but on the same bus? I have 5 queues on the same bus and each queue might have a message with an message id of ex. 100

var sequenceToCancel = await queueClient.ScheduleMessageAsync(message, endTime);

doesn't return anything!

And the whole stack trace kinda just poops out without finishing anything above in the code stack!

The message is put into the service bus queue but the method doesn't return! I tried putting a try catch around it but that didn't do anything and no exception gets thrown up the stack in the controller. The whole stack all the way up to the controller just kinda poops out! So no code after this method in the controller gets run.

What would cause this and how can I check to see if there are any errors anywhere?

Here is the full method.

public async Task < long > CreatePostEventEmailMessage(int eventId, DateTime eventDateTime, YogaSpaceDuration duration, DateTime utcEventDateTime) {
  string serviceBusConnectionString = System.Configuration.ConfigurationManager.AppSettings["ServiceBusConnectionString"];
  string queueName = System.Configuration.ConfigurationManager.AppSettings["PostEventEmailQueueName"];

  var queueClient = QueueClient.CreateFromConnectionString(serviceBusConnectionString, queueName);

  int length = Convert.ToInt32(EnumHelper.GetDisplayName(duration).Split(' ')[0]); // end of class
  var endTime = DateTime.SpecifyKind(utcEventDateTime.AddMinutes(length).AddMinutes(1), DateTimeKind.Utc);
  BrokeredMessage message = new BrokeredMessage(eventId.ToString());
  message.MessageId = eventId.ToString();
  message.ScheduledEnqueueTimeUtc = endTime;
  var sequenceToCancel = await queueClient.ScheduleMessageAsync(message, new DateTimeOffset(endTime));
  await queueClient.CloseAsync(); // this line never gets hit

  return sequenceToCancel; // this line never gets hit
}

FYI - funny thing is just above this method I have another method that does the same thing on another queue and it works fine! So I'm looking to see if something has a misspelled name or is configured incorrectly, but what's frsutrating is if that is the case I would think that I would see an exception or the message wouldn't be placed on the queue?

chuckd
  • 13,460
  • 29
  • 152
  • 331
  • What is the value of `endTime` at the line right before the one that never gets hit? Also maybe add the code for `ScheduleMessageAsync` – Rafalon Jul 09 '18 at 06:33
  • `endTime` is fine, adds the message ok to the queue and `ScheduleMessageAsync` is a MS library function – chuckd Jul 09 '18 at 06:39
  • Not sure, but `endTime` is supposed to be a `DateTimeOffset`, and here it looks like it's a `DateTime`. Are you sure that the conversion is made the way you think it is? Did you really make it this way in the working method? – Rafalon Jul 09 '18 at 06:59
  • oh, you might have something here! I'll have to make some changes. Will post any results I get if that fixes it! Thanks for the advice! – chuckd Jul 09 '18 at 07:05
  • Rafalon - quick question, what would be the dateTimeOffset of this value be? I can get the dateTime for `ScheduledEnqueuerTimeUtc` but what woul;d be it's offset? – chuckd Jul 09 '18 at 07:07
  • I don't really know, I never used `DateTimeOffset` to be honest. I'm just throwing here what I think *could* be a problem. Again, how did you initialize `endTime` in the method that works for you? – Rafalon Jul 09 '18 at 07:13
  • `endTime` is a date time coming in from the database, so I believe it's ok. I've also looked at the value before it gets passed and it looks good. But I could be wrong, do you want me to post a value for `endTime`? – chuckd Jul 09 '18 at 07:25

1 Answers1

0

Yes, it is possible to have the same 'MessageId' for each message in different queues.

queueClient.ScheduleMessageAsync() 

returns the 'SequenceNumber' of the message sent to the queue.

There might be a problem in handling the asynchronous call. Check whether the parent method is an asynchronous method.

Balasubramaniam
  • 371
  • 5
  • 14