static async Task Deadletter() { try { string ServiceBusConnectionString = "Endpoint=sb://pricechange.servicebus.windows.net/;SharedAccessKeyName=cartitempricechange;SharedAccessKey=zOK+zZifCv4xX4f0af4Bctrg6tXeLKvwD9vhBT9YlZ8="; string TopicName = "pricechange-topic"; string SubscriptionName = "pricechange-topic-subscription"; MessagingFactory factory = MessagingFactory.CreateFromConnectionString(ServiceBusConnectionString); string path = Microsoft.ServiceBus.Messaging.SubscriptionClient.FormatDeadLetterPath(TopicName, SubscriptionName); Microsoft.ServiceBus.Messaging.MessageReceiver deadletterReceiver = factory.CreateMessageReceiver(path); BrokeredMessage msg = deadletterReceiver.Receive(); if (msg != null) { var messageBody = new StreamReader(msg.GetBody <Stream>(), Encoding.UTF8).ReadToEnd(); var receivedMessage = JsonConvert.DeserializeObject <ServiceBusMessage>(messageBody); Console.WriteLine($"Received message: UserInfo:{receivedMessage.Id}"); Console.ReadKey(); msg.Complete(); } } catch (Exception ex) { throw ex; } }
protected override IAsyncResult OnBeginComplete(TimeSpan timeout, AsyncCallback callback, object state) { this.TraceComplete(); Microsoft.ServiceBus.Messaging.MessageReceiver messageReceiver = this.receiver; Guid[] guidArray = new Guid[] { this.lockToken }; return(messageReceiver.BeginComplete(guidArray, timeout, callback, state)); }
protected override void OnAbort() { Microsoft.ServiceBus.Messaging.MessageReceiver messageReceiver = this.messageReceiver; if (messageReceiver != null) { messageReceiver.Abort(); } }
protected override void OnClose(TimeSpan timeout) { try { Microsoft.ServiceBus.Messaging.MessageReceiver messageReceiver = this.messageReceiver; if (messageReceiver != null) { messageReceiver.Close(timeout); } } catch (Exception exception) { this.OnException(exception); throw; } }
public MessageReceiver(Microsoft.ServiceBus.Messaging.MessageReceiver receiverCore) { messageReceiverCore = receiverCore; }
public static ServiceBusInputChannelBase <TChannel> .AfmsReceiveContext ApplyTo(Message message, Microsoft.ServiceBus.Messaging.MessageReceiver receiver, Guid lockToken) { ServiceBusInputChannelBase <TChannel> .AfmsReceiveContext afmsReceiveContext = new ServiceBusInputChannelBase <TChannel> .AfmsReceiveContext() { receiver = receiver, lockToken = lockToken }; message.Properties.Add(System.ServiceModel.Channels.ReceiveContext.Name, afmsReceiveContext); return(afmsReceiveContext); }