internal static Message HelpReceive(IInputChannel channel, TimeSpan timeout) { Message message; if (!channel.TryReceive(timeout, out message)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(Microsoft.ServiceBus.Channels.InputChannel.CreateReceiveTimedOutException(channel, timeout)); } return(message); }
internal static Message HelpReceive(IInputChannel channel, TimeSpan timeout) { Message message; if (channel.TryReceive(timeout, out message)) { return(message); } else { throw CreateReceiveTimedOutException(channel, timeout); } }
internal static Message HelpReceive(IInputChannel channel, TimeSpan timeout) { Message message; if (channel.TryReceive(timeout, out message)) { return(message); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateReceiveTimedOutException(channel, timeout)); } }
static void Main(string[] args) { try { Options options = new Options(args); AmqpBinaryBinding binding = new AmqpBinaryBinding(); binding.BrokerHost = options.Broker; binding.BrokerPort = options.Port; binding.TransferMode = TransferMode.Streamed; IChannelFactory <IInputChannel> factory = binding.BuildChannelFactory <IInputChannel>(); factory.Open(); try { System.ServiceModel.EndpointAddress addr = options.Address; IInputChannel receiver = factory.CreateChannel(addr); receiver.Open(); TimeSpan timeout = options.Timeout; System.ServiceModel.Channels.Message message; while (receiver.TryReceive(timeout, out message)) { AmqpProperties props = (AmqpProperties)message.Properties["AmqpProperties"]; Console.WriteLine("Message(properties=" + MessagePropertiesAsString(props) + ", content='" + MessageContentAsString(message, props) + "')"); } } finally { factory.Close(); } } catch (Exception e) { Console.WriteLine("Drain: " + e); } }
void ProcessRequestOrInput(IInputChannel input) { while (true) { if (!loop) { return; } if (receive_synchronously) { Message msg; if (input.TryReceive(receive_timeout, out msg)) { ProcessInput(input, msg); } } else { input.BeginTryReceive(receive_timeout, TryReceiveDone, input); loop_handle.WaitOne(receive_timeout); } } }
void ProcessRequestOrInput (IInputChannel input) { while (true) { if (!loop) return; if (receive_synchronously) { Message msg; if (input.TryReceive (receive_timeout, out msg)) ProcessInput (input, msg); } else { input.BeginTryReceive (receive_timeout, TryReceiveDone, input); loop_handle.WaitOne (receive_timeout); } } }
private Message ReceiveMessage(IInputChannel channel, bool commit) { Message message = null; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { bool messageDetected = false; if (this.Parameters.AsyncWaitForMessage) { IAsyncResult result = channel.BeginWaitForMessage(this.Parameters.WaitForMessageTimeout, null, null); messageDetected = channel.EndWaitForMessage(result); } else { messageDetected = channel.WaitForMessage(this.Parameters.WaitForMessageTimeout); } if (this.Parameters.WaitForMessage) { lock (this.Results) { this.Results.Add(String.Format("WaitForMessage returned {0}", messageDetected)); } } if (messageDetected) { if (this.Parameters.AsyncReceive) { if (this.Parameters.TryReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); bool ret = channel.EndTryReceive(result, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { IAsyncResult result = channel.BeginReceive(this.Parameters.ReceiveTimeout, null, null); message = channel.EndReceive(result); } catch (TimeoutException) { message = null; } } } else { if (this.Parameters.TryReceive) { bool ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { message = channel.Receive(this.Parameters.ReceiveTimeout); } catch (TimeoutException) { message = null; } } } } else { if (this.Parameters.TryReceive) { bool ret = false; if (this.Parameters.AsyncReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); if (this.Parameters.TryReceiveNullIAsyncResult) { try { channel.EndTryReceive(null, out message); } catch (Exception e) { lock (this.Results) { this.Results.Add(String.Format("TryReceive threw {0}", e.GetType().Name)); } } } ret = channel.EndTryReceive(result, out message); } else { ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); } lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); this.Results.Add(String.Format("Message was {0}", (message == null ? "null" : "not null"))); } } message = null; } if (commit && message != null) { lock (this.Results) { this.Results.Add(String.Format("Received message with Action '{0}'", message.Headers.Action)); } ts.Complete(); } else { Transaction.Current.Rollback(); } } return message; }
private Message ReceiveMessage(IInputChannel channel, bool commit) { Message message = null; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { bool messageDetected = false; if (this.Parameters.AsyncWaitForMessage) { IAsyncResult result = channel.BeginWaitForMessage(this.Parameters.WaitForMessageTimeout, null, null); messageDetected = channel.EndWaitForMessage(result); } else { messageDetected = channel.WaitForMessage(this.Parameters.WaitForMessageTimeout); } if (this.Parameters.WaitForMessage) { lock (this.Results) { this.Results.Add(String.Format("WaitForMessage returned {0}", messageDetected)); } } if (messageDetected) { if (this.Parameters.AsyncReceive) { if (this.Parameters.TryReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); bool ret = channel.EndTryReceive(result, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { IAsyncResult result = channel.BeginReceive(this.Parameters.ReceiveTimeout, null, null); message = channel.EndReceive(result); } catch (TimeoutException) { message = null; } } } else { if (this.Parameters.TryReceive) { bool ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { message = channel.Receive(this.Parameters.ReceiveTimeout); } catch (TimeoutException) { message = null; } } } } else { if (this.Parameters.TryReceive) { bool ret = false; if (this.Parameters.AsyncReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); if (this.Parameters.TryReceiveNullIAsyncResult) { try { channel.EndTryReceive(null, out message); } catch (Exception e) { lock (this.Results) { this.Results.Add(String.Format("TryReceive threw {0}", e.GetType().Name)); } } } ret = channel.EndTryReceive(result, out message); } else { ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); } lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); this.Results.Add(String.Format("Message was {0}", (message == null ? "null" : "not null"))); } } message = null; } if (commit && message != null) { lock (this.Results) { this.Results.Add(String.Format("Received message with Action '{0}'", message.Headers.Action)); } ts.Complete(); } else { Transaction.Current.Rollback(); } } return(message); }