Method: Mongo::Monitoring::Subscribable#subscribe

Defined in:
lib/mongo/monitoring.rb

#subscribe(topic, subscriber) ⇒ Object

Note:

It is possible to subscribe the same listener to the same topic

Subscribe a listener to an event topic.

multiple times, in which case the listener will be invoked as many times as it is subscribed and to unsubscribe it the same number of unsubscribe calls will be needed.

Examples:

Subscribe to the topic.

monitoring.subscribe(QUERY, subscriber)

Subscribe to the topic globally.

Monitoring::Global.subscribe(QUERY, subscriber)

Parameters:

  • topic (String)

    The event topic.

  • subscriber (Object)

    The subscriber to handle the event.

Since:

  • 2.1.0



105
106
107
# File 'lib/mongo/monitoring.rb', line 105

def subscribe(topic, subscriber)
  subscribers_for(topic).push(subscriber)
end