 
     queue.bind EXCHANGENAME, '#', =>
       @log 'bounded to exchange', EXCHANGENAME
-      queue.subscribe @_handleNewMessage.bind this
-
-
-  _handleNewMessage: (message, header, property) ->
+      queue.subscribe @_handleMqMessage.bind this
+
+
+  # --- mq handlers
+
+  _handleMqMessage: (message, header, property) ->
 
     [ err, parsedMessage ] = @_parseMessage message.data.toString()
-
-    if err
-      @log 'failed to parse message', err
-      @log 'message was', message
-
-    else
-      @log 'got message', parsedMessage
-      for id of @_verifiedConnections
-        @_connections[id].write parsedMessage.message
-
+    return @log 'got message but failed to parse', message  if err
+
+    @log 'got message for', property.routingKey, parsedMessage
+
+    [ t_group, t_user ] = property.routingKey.split ':'
+    for route in @_verifiedRoutes
+      [ group, user, id ] = route
+      if group is t_group
+        return  if t_user? and t_user isnt user
+        @_connections[id]?.write JSON.stringify parsedMessage
+
+
+  # --- express app handlers for internal use
+
+  _handleSendNotification: (scope) -> (req, res) =>
+
+    @log "got hit on send -- #{scope}", req.body
+
+    { groupName, account, body } = req.body
+
+    if scope is 'group'
+      if groupName
+        routingKey = groupName
+      else
+        return res.sendStatus 500
+
+    else if scope is 'user'
+      if (groupName = body?.context) and (username = account?.nick)
+        routingKey = "#{groupName}:#{username}"
+      else
+        return res.sendStatus 500
+
+    @sendNotification routingKey, body
+
+    res.sendStatus 200
+
+
+  _handleStatusRequest: (req, res) ->
+
+    res.send """
+      <pre>
+        NotificationWorker #{argv.i ? 0} is #{if @isReady() then '' else 'not '}ready
+        Connections: #{JSON.stringify @_verifiedConnections}
+        Routes: #{JSON.stringify @_verifiedRoutes}
+      </pre>
+    """
+
+
+  # --- socket handlers
 
   _handleSocketConnection: (connection) ->
 

  _handleSocketMessage: (connection, message) ->

    @log 'got socket message', message
    @_proccessMessage connection, message


  _handleSendNotification: (req, res) ->

    @log 'got hit on send'
    res.send 'NotificationWorker is OK'


  _parseMessage: (message) ->


    @_app.use helmet()
    @_app.use cors()

    @_app.get  '/notify',                  @_handleStatusRequest.bind this
    @_app.post '/dispatcher_notify_user',  @_handleSendNotification 'user'
    @_app.post '/dispatcher_notify_group', @_handleSendNotification 'group'

    return @_app


  _startServer: ->
