anchor.diff:  open MassTransit.Async.Queue
   open MassTransit.Async.AsyncRetry
   
  +type internal Agent<'T> = MailboxProcessor<'T>
  +
   /// Create a new receiver, with a queue description,
   /// a factory for messaging factories and some control flow data
   type Receiver(desc   : QueueDescription,
  
positive.code:             logger.Debug("received message")
              messages.Add bmsg
            else
              logger.Debug("got null msg due to timeout receiving") }
  
    /// Starts (stop-1)/100 new clients and message factories, so for stop=501
    /// it loops 500 times and starts 5 new clients
  
negative.code:       if not(recv.IsClosed) then
          try recv.Close()
          with | x -> logger.Error("could not close receiver", x)
          
    /// cleans out the message buffer and disposes all messages therein
    let clearLocks () = 
      while messages.Count > 0 do
        async {
          let m = ref null
          if messages.TryTake(m, TimeSpan.FromMilliseconds(4.0)) then 
            try 
              do! Async.FromBeginEnd((!m).BeginAbandon, (!m).EndAbandon)
              (!m).Dispose()
            with 
            | x ->
              let entry = sprintf "could not abandon message#%s" <| (!m).MessageId
              logger.Error(entry, x) }
          |> Async.Start
  
  
    /// Starts the receiver which starts the consuming from the service bus
    /// and creates the queue if it doesn't exist
    member x.Start () =
      logger.InfoFormat("start called for queue '{0}'", desc)
      if started then ()
      else started <- true
      start ()
  
    /// Stops the receiver; allowing it to start once again.
    member x.Stop () =
      logger.InfoFormat("stop called for queue '{0}'", desc)
      if not(started) then ()
      else 
        started <- false
        Async.CancelDefaultToken ()
  
    /// Returns a message if one was added to the buffer within the timeout specified,
    /// or otherwise returns null.
    member x.Get(timeout : TimeSpan) =
      let mutable item = null
      let _ = messages.TryTake(&item, timeout.Milliseconds)
      item
  
    /// Tries to take an item from the list of messages
    member internal __.TryTake(?timeout) =
      let timeout = defaultArg timeout <| TimeSpan.FromMilliseconds 50.0
      let mutable item = null
      if messages.TryTake(&item, timeout.Milliseconds)
  