An object for subscribing to frame messages.

@param {String} [opts.channel=default] - The name of the messaging channel to
subscribe to.
502953
function Subscriber(opts) {
  opts = opts || {};

  this._channel = opts.channel || 'default';
  this._subscribers = [];

  /* for mocking */
  var addEventListener = opts.addEventListener || window.addEventListener;
  var attachEvent = opts.attachEvent || window.attachEvent;

  var _this = this;
  function onMessage(e) {
    var event = parse(e.data);
    if (event.channel === _this._channel) {
      for (var i = 0, len = _this._subscribers.length; i < len; i++) {
        _this._subscribers[i].apply({}, event.args);
      }
    }
  }

  if (addEventListener) {
    addEventListener('message', onMessage, false);
  } else {
    attachEvent('onmessage', onMessage, false);
  }
}
1328250
function (fn, create, update) {
  var subscriber = new Subscription(fn, update, this);

  // Immediately alias the starting value.
  subscriber.value = subscriber.execute();
  Utils.isFunction(create) && (subscriber.value = create(subscriber.value));

  return subscriber;
}
884854
@Override
	public Promise subscribe(String channel) {
		try {

			// Create publisher
			createOrGetPublisher(channel);

			// Create subscriber
			synchronized (subscribers) {
				if (!subscribers.containsKey(channel)) {
					TopicSubscriber subscriber = session.createSubscriber(session.createTopic(channel));
					subscribers.put(channel, subscriber);
					subscriber.setMessageListener((message) -> {
						try {
							BytesMessage msg = (BytesMessage) message;
							byte[] bytes = new byte[(int) msg.getBodyLength()];
							msg.readBytes(bytes);
							received(channel, bytes);
						} catch (Exception cause) {
							logger.error("Unable to deserialize message!", cause);
						}
					});
				}
			}
		} catch (Exception cause) {
			return Promise.reject(cause);
		}
		return Promise.resolve();
	}
1181448
function channel(name) {
    if (0 === arguments.length) {
        if (!this._channel) this._channel = postal.channel();
        return this._channel;
    } else {
        this._channel = postal.channel(name);
    }
    return this;
}
117011
function(channel, fn, context){
      if (!channels[channel]) return;

      var subscription;
      for (var i = 0; i < channels[channel].length; i++) {
        subscription = channels[channel][i];
        if (subscription.fn === fn && subscription.context === context) {
          channels[channel].splice(i, 1);
          i--;
        }
      }
    }
632013
function subscribe() {
  console.log('Subscribing client ' + clientId + ' to topic: ' + topics.subscribe);
  client.subscribe(topics.subscribe);
  isSubscribed = true;
}
1225804
@Override
	public Promise subscribe(String channel) {
		try {

			// Create topic
			ProjectTopicName topicName = ProjectTopicName.of(projectID, channel);
			Topic topic = null;
			try {
				topic = topicAdmin.getTopic(topicName);
			} catch (NotFoundException notFound) {
			}
			if (topic == null) {
				topic = topicAdmin.createTopic(topicName);
				logger.info("Topic \"" + topic.getName() + "\" created successfully.");
			}

			// Create subscription
			String nodeSubscription;
			if (channel.endsWith('.' + nodeID)) {
				nodeSubscription = channel;
			} else {
				nodeSubscription = channel + '-' + nodeID;
			}
			ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectID, nodeSubscription);
			Subscription subscription = null;
			try {
				subscription = subscriptionAdmin.getSubscription(subscriptionName);
			} catch (NotFoundException notFound) {
			}
			if (subscription == null) {
				subscription = subscriptionAdmin.createSubscription(subscriptionName, topicName,
						PushConfig.getDefaultInstance(), ackDeadlineSeconds);
				logger.info("Subscription \"" + subscription.getName() + "\" created successfully.");
			}

			// Create subscriber
			synchronized (subscribers) {
				if (!subscribers.containsKey(nodeSubscription)) {
					Subscriber.Builder builder = Subscriber.newBuilder(subscriptionName, (message, consumer) -> {

						// Message received
						try {

							// We are running in a netty executor's pool,
							// do not create new task.
							processReceivedMessage(channel, message.getData().toByteArray());
						} finally {
							consumer.ack();
						}

					});
					if (channelProvider != null) {
						builder.setChannelProvider(channelProvider);
					}
					if (credentialsProvider != null) {
						builder.setCredentialsProvider(credentialsProvider);
					}
					if (executorProvider != null) {
						builder.setExecutorProvider(executorProvider);
						builder.setSystemExecutorProvider(executorProvider);
					} else {
						builder.setExecutorProvider(defaultExecutorProvider);
						builder.setSystemExecutorProvider(defaultExecutorProvider);
					}
					if (headerProvider != null) {
						builder.setHeaderProvider(headerProvider);
					}
					if (maxAckExtensionPeriod != null) {
						builder.setMaxAckExtensionPeriod(maxAckExtensionPeriod);
					}
					if (parallelPullCount > 0) {
						builder.setParallelPullCount(parallelPullCount);
					}
					if (flowControlSettings != null) {
						builder.setFlowControlSettings(flowControlSettings);
					}
					Subscriber subscriber = builder.build();
					subscriber.startAsync();
					subscribers.put(nodeSubscription, subscriber);
					logger.info(
							"Subscriber created for subscription \"" + subscriber.getSubscriptionNameString() + "\".");
				}
			}

		} catch (Exception cause) {
			return Promise.reject(cause);
		}
		return Promise.resolve();
	}
819317
def incoming(message, callback)
      if message['channel'] == '/meta/subscribe'
        authenticate_subscribe(message)
      elsif message['channel'] !~ %r{^/meta/}
        authenticate_publish(message)
      end
      callback.call(message)
    end
879458
def subscribe(self, destination, id, ack='auto', headers=None, **keyword_headers):
        
        self.transport.subscriptions[id] = destination
1139008
function subscribe (channels) {
    channels.forEach(channel => {
      if (~_subscribedChannels.indexOf(channel)) return
      _subscribedChannels.push(channel)
      if (_socket) _socket.subscribe(channel)
    })
    return connection
  }
670984
function psubscribe(conn, channels) {
  return this.doSubscribe(
    PUBSUB.PSUBSCRIBE,
    PUBSUB.PATTERNS,
    this._patterns, conn, channels);
}
333792
function(channel, subscription, context, once) {
      if (!channels[channel]) channels[channel] = [];
      channels[channel].push({fn: subscription, context: context || this, once: once});
    }
485597
function subscribeNode (client, subscriptions, channel, callback, done_callback) {
    if (subscriptions[channel]===undefined) {
        subscriptions[channel] = [callback];
        client.subscribe(channel, {qos: 0}, function() {
            // If there is a done_callback defined, execute it
            if (done_callback!==undefined) done_callback();
        });
    } else {
        subscriptions[channel].push(callback);
    }
}
1185247
function init(client, opts) {
	client.servers = {};
	client.channels = {};
	client.users = {};
	client.directMessages = {};
	client.internals = {
		oauth: {},
		version: CURRENT_VERSION,
		settings: {}
	};
	client._connecting = true;

	setupPing(client.internals);
	return getToken(client, opts);
}
927613
void reSubscribeByName(EventChannelStruct event_channel_struct, String name) {
        Enumeration callback_structs = event_callback_map.elements();
        while (callback_structs.hasMoreElements()) {
            EventCallBackStruct callback_struct = (EventCallBackStruct) callback_structs.nextElement();
            if (callback_struct.channel_name.equals(name)) {
                reSubscribe(event_channel_struct, callback_struct);
            }
        }
    }
886821
function subscribe() {
  openSTNotification.subscribeEvent.rabbit(
    ['#'],
    {queue: 'openst_platform'},
    function (msgContent) {
      logger.debug('[RECEIVED]', msgContent, '\n');
    }
  ).catch(function (err) {
    logger.error(err);
  });
}
750359
function(message) {
			var response = new DataResponse(message, subscribe, subscribeError);
			if (queueSubUnsubRequest(message, response) === 1) {
				fireFirstSubUnsubEvent(message.itemName);
			} else {
				that.emit("subscribeInQueue", message.itemName);
			}
		}