Example of creating a pull subscription for a topic.
517948
public Subscription createSubscription(String topicId, String subscriptionId) throws Exception {
    // [START pubsub_create_pull_subscription]
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
      // eg. projectId = "my-test-project", topicId = "my-test-topic"
      ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
      // eg. subscriptionId = "my-test-subscription"
      ProjectSubscriptionName subscriptionName =
          ProjectSubscriptionName.of(projectId, subscriptionId);
      // create a pull subscription with default acknowledgement deadline
      Subscription subscription =
          subscriptionAdminClient.createSubscription(
              subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
      return subscription;
    }
    // [END pubsub_create_pull_subscription]
  }
958902
def register_subscriber(topic, topic_type)
      code, message,val = @proxy.registerSubscriber(@caller_id,
                                                    topic,
                                                    topic_type,
                                                    @slave_uri)
      if code == 1
        val
      elsif code == 0
        puts message
        val
      else
        raise message
      end
    end
632013
function subscribe() {
  console.log('Subscribing client ' + clientId + ' to topic: ' + topics.subscribe);
  client.subscribe(topics.subscribe);
  isSubscribed = true;
}
763549
final PullResponse pull(
      ProjectSubscriptionName subscription, boolean returnImmediately, int maxMessages) {

    PullRequest request =
        PullRequest.newBuilder()
            .setSubscription(subscription == null ? null : subscription.toString())
            .setReturnImmediately(returnImmediately)
            .setMaxMessages(maxMessages)
            .build();
    return pull(request);
  }
445061
def _handle_subscription(self, topics):
        """"""
        if not isinstance(topics, list):
            topics = [topics]
        for topic in topics:
            topic_levels = topic.split('/')
            try:
                qos = int(topic_levels[-2])
            except ValueError:
                qos = 0
            try:
                _LOGGER.debug('Subscribing to: %s, qos: %s', topic, qos)
                self._sub_callback(topic, self.recv, qos)
            except Exception as exception:  # pylint: disable=broad-except
                _LOGGER.exception(
                    'Subscribe to %s failed: %s', topic, exception)
645409
def create_subscription(subscription_params = {})
      created_at = Time.current
      if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
        subscription_params[:subscribing_to_email] = subscription_params[:subscribing] 
      end
      subscription = subscriptions.new(subscription_params)
      subscription.subscribing? ?
        subscription.assign_attributes(subscribing: true, subscribed_at: created_at) :
        subscription.assign_attributes(subscribing: false, unsubscribed_at: created_at)
      subscription.subscribing_to_email? ?
        subscription.assign_attributes(subscribing_to_email: true, subscribed_to_email_at: created_at) :
        subscription.assign_attributes(subscribing_to_email: false, unsubscribed_to_email_at: created_at)
      subscription.optional_targets = (subscription.optional_targets || {}).with_indifferent_access
      optional_targets = {}.with_indifferent_access
      subscription.optional_target_names.each do |optional_target_name|
        optional_targets = subscription.subscribing_to_optional_target?(optional_target_name) ?
          optional_targets.merge(
            Subscription.to_optional_target_key(optional_target_name) => true,
            Subscription.to_optional_target_subscribed_at_key(optional_target_name) => created_at
          ) :
          optional_targets.merge(
            Subscription.to_optional_target_key(optional_target_name) => false,
            Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => created_at
          )
      end
      subscription.assign_attributes(optional_targets: optional_targets)
      subscription.save ? subscription : nil
    end
753257
def community_post_subscription_create(self, post_id, data, **kwargs):
        ""
        api_path = "/api/v2/community/posts/{post_id}/subscriptions.json"
        api_path = api_path.format(post_id=post_id)
        return self.call(api_path, method="POST", data=data, **kwargs)
635818
def subscribe(topic, protocol, endpoint, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    conn.subscribe(get_arn(topic, region, key, keyid, profile), protocol, endpoint)
    log.info('Subscribe %s %s to %s topic', protocol, endpoint, topic)
    try:
        del __context__[_subscriptions_cache_key(topic)]
    except KeyError:
        pass
    return True
1039295
function Subscription(name, topic) {
            this._pattern = "%s://%s.mns.%s.aliyuncs.com/topics/%s/subscriptions/%s";
            this._name = name;
            this._topic = topic;
            // make url
            this._urlAttr = this.makeAttrURL();
            // create the OpenStack object
            this._openStack = new AliMNS.OpenStack(topic.getAccount());
        }
856781
def subscribe(topic_name, topic_type, &callback)
      sub = Subscriber.new(@node_name,
                           resolve_name(topic_name),
                           topic_type,
                           callback)
      @manager.add_subscriber(sub)
      trap_signals
      sub
    end
756954
@Override
	public TopicSubscriber createDurableSubscriber(Topic topic, String subscriptionName, String messageSelector, boolean noLocal) throws JMSException
    {
    	return createDurableSubscriber(idProvider.createID(), topic, subscriptionName, messageSelector, noLocal);
    }
1303899
def create_event_subscription(self, url):
        
        params = {'callbackUrl': url}
        response = self._do_request('POST', '/v2/eventSubscriptions', params)
        return response.json()
755460
public function createSubscription()
    {
        $data = [
            "customer" => request()->customer, //Customer email or code
            "plan" => request()->plan,
            "authorization" => request()->authorization_code
        ];

        $this->setRequestOptions();
        $this->setHttpResponse('/subscription', 'POST', $data);
    }
730546
function subscriptionDispatcher (topic, data, options, subscriptions) {
    var
      resolver = createResolver(),
      fulfill = resolveUse('fulfilledValues', 'fulfilled', options, resolver),
      reject = resolveUse('rejectedValues', 'rejected', options, resolver);

    resolver.i = subscriptions.length - 1;
    resolver.resume = {
      topic: topic,
      data: data,
      subscriptions: subscriptions,
      fulfill: fulfill,
      reject: reject
    };

    resumeSubscriptionDispatcher(
      topic, data, options, subscriptions, resolver, fulfill, reject
    );
    evaluateLatch(resolver, options);

    return resolver.promise;
  }
178767
def assign(self, subject):
        
        if not isinstance(subject, (Publisher, Subscriber)):
            raise TypeError('Assignee has to be Publisher or Subscriber')

        # check if not already assigned
        if self._subject is not None:
            raise SubscriptionError('Topic %r already assigned' % self._path)

        self._subject = subject

        # subscribe to subject if topic has subscriptions
        if self._subscriptions:
            self._subject.subscribe(self)

        # if topic received emits before assignment replay those emits
        if self._pre_assign_emit is not None:
            for value in self._pre_assign_emit:
                self._subject.emit(value, who=self)
            self._pre_assign_emit = None

        return subject
1067274
def parse_topic(self, params, region, topic):
        
        topic['arn'] = topic.pop('TopicArn')
        topic['name'] = topic['arn'].split(':')[-1]
        (prefix, partition, service, region, account, name) = topic['arn'].split(':')
        api_client = api_clients[region]
        attributes = api_client.get_topic_attributes(TopicArn=topic['arn'])['Attributes']
        for k in ['Owner', 'DisplayName']:
            topic[k] = attributes[k] if k in attributes else None
        for k in ['Policy', 'DeliveryPolicy', 'EffectiveDeliveryPolicy']:
            topic[k] = json.loads(attributes[k]) if k in attributes else None
        topic['name'] = topic['arn'].split(':')[-1]
        manage_dictionary(topic, 'subscriptions', {})
        manage_dictionary(topic, 'subscriptions_count', 0)
        self.topics[topic['name']] = topic
1236284
def create(self, callback_url):
        
        resource = self.resource.create({'subscribed_to': 'address',
                                         'callback_url': callback_url})
        subscription = self.wrap(resource)
        self.add(subscription)
        return subscription