Skip to content

Instantly share code, notes, and snippets.

@jtaubensee
Last active June 30, 2016 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtaubensee/57c2b9d3177059a7bc18b4d8510e290f to your computer and use it in GitHub Desktop.
Save jtaubensee/57c2b9d3177059a7bc18b4d8510e290f to your computer and use it in GitHub Desktop.
Service Bus messaging - Use AMQP to schedule and cancel messages
static async Task ScheduleMessagesSample(string serviceBusConnectionString)
{
// Set transport type to AMQP
var builder = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
builder.TransportType = TransportType.Amqp;
// Create queue
NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(builder.ToString());
QueueDescription queueDescription = new QueueDescription("myqueue") { EnablePartitioning = true };
namespaceManager.CreateQueue(queueDescription);
// Create queue client
MessagingFactory factory = MessagingFactory.CreateFromConnectionString(builder.ToString());
QueueClient queueClient = factory.CreateQueueClient(queueDescription.Path);
// Schedule message
BrokeredMessage message = new BrokeredMessage("Hello");
long sequenceNumber = await queueClient.ScheduleMessageAsync(message, DateTime.Now + TimeSpan.FromMinutes(10));
// Cancel scheduled message
await queueClient.CancelScheduledMessageAsync(sequenceNumber);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment