# File lib/stomp_server/queue_manager.rb, line 171
  def sendmsg(frame)
    frame.command = "MESSAGE"
    dest = frame.headers['destination']
    puts "Sending a message to #{dest}: #{frame}"
    # Lookup a user willing to handle this destination
    available_users = @queues[dest].reject{|user| @pending[user.connection]}
    if available_users.empty?
      @qstore.enqueue(dest,frame)
      return
    end

    # Look for a user with ack (we favor reliability)
    reliable_user = available_users.find{|u| u.ack}

    if reliable_user
      # give it a message-id
      @qstore.assign_id(frame, dest)
      send_to_user(frame, reliable_user)
    else
      random_user = available_users[rand(available_users.length)]
      # Note message-id header isn't set but we won't need it anyway
      # <TODO> could break some clients: fix this
      send_to_user(frame, random_user)
    end
  end