Subscribes to a subject.

@param args the subject, cluster info, and subscription options
767385
public static void main(String[] args) throws Exception {
        try {
            new Subscriber(args).run();
        } catch (IllegalArgumentException e) {
            System.out.flush();
            System.err.println(e.getMessage());
            Subscriber.usage();
            System.err.flush();
            throw e;
        }
    }
972315
public static void main(String[] args) {
    // ScaleCube Node node with no members
    Microservices seed =
        Microservices.builder()
            .discovery(ScalecubeServiceDiscovery::new)
            .transport(ServiceTransports::rsocketServiceTransport)
            .startAwait();

    // Construct a ScaleCube node which joins the cluster hosting the Greeting Service
    Microservices microservices =
        Microservices.builder()
            .discovery(
                serviceEndpoint ->
                    new ScalecubeServiceDiscovery(serviceEndpoint)
                        .options(opts -> opts.seedMembers(toAddress(seed.discovery().address()))))
            .transport(ServiceTransports::rsocketServiceTransport)
            .services(new GreetingServiceImpl())
            .startAwait();

    // Create service proxy
    GreetingsService service = seed.call().api(GreetingsService.class);

    // Execute the services and subscribe to service events
    service
        .sayHello("joe")
        .subscribe(
            consumer -> {
              System.out.println(consumer.message());
            });

    // shut down the nodes
    seed.shutdown().block();
    microservices.shutdown().block();
  }
1036354
public <T extends EventListener> void subscribe(EventPublisher source, T listener) {
	if (source == null || listener == null) {
	    throw new IllegalArgumentException("Parameters cannot be null");
	}
	log.debug("[subscribe] Adding {} --> {}", source.getClass().getName(), listener.getClass().getName());

	GenericEventDispatcher<T> dispatcher = (GenericEventDispatcher<T>) dispatchers.get(source);
	if (dispatcher == null) {
	    log.warn("[subscribe] Registering with a disconnected source");
	    dispatcher = createDispatcher(source);
	}

	dispatcher.addListener(listener);

    }
303036
public static void main(String[] args) {
    System.exit(getConf(
        ClientContext.create(new InstancedConfiguration(ConfigurationUtils.defaults())), args));
  }
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();
	}
293951
@Override
	public TopicSubscriber createSubscriber(Topic topic) throws JMSException
    {
        return createSubscriber(topic,null,false);
    }
815777
def add_subscriber(subscriber)
      uris = @master.register_subscriber(subscriber.topic_name,
                                         subscriber.topic_type.type)
      subscriber.set_manager(self)
      uris.each do |publisher_uri|
        subscriber.add_connection(publisher_uri)
      end
      @subscribers.push(subscriber)
      subscriber
    end
198085
@VisibleForTesting
  synchronized void consumerSubscriptionRebalance() {
    log.debug("Subscribed Topics " + this.consumer.subscription());
    if (!this.subscribedTopics.isEmpty()) {
      final Iterator<String> iter = this.subscribedTopics.iterator();
      final List<String> topics = new ArrayList<>();
      while (iter.hasNext()) {
        topics.add(iter.next());
      }
      this.subscribedTopics.clear();
      //re-subscribe topics that are needed
      this.consumer.subscribe(topics);
    }
  }
34562
public void setArgs(final Serializable... args) {
		this.args = args == null || args.length == 0 ? null : args;
	}
838804
protected void addSubscription(SIBUuid12 topicSpace, String topic, MESubscription subscription)
  {
    // Generate a key for the topicSpace/topic
    final String key = BusGroup.subscriptionKey(topicSpace, topic);

    iProxies.put(key, subscription);
  }
651538
private void publish2Subscribers(String topic, AbstractMessage.QOSType qos, ByteBuffer origMessage, boolean retain, Integer messageID) {
        Log.trace("publish2Subscribers republishing to existing subscribers that matches the topic {}", topic);
        if (Log.DEBUG) {
            Log.trace("content <{}>", DebugUtils.payload2Str(origMessage));
            Log.trace("subscription tree {}", subscriptions.dumpTree());
        }
        for (final Subscription sub : subscriptions.matches(topic)) {
            if(m_clientIDs.get(sub.getClientId()) == null) {
                subscriptions.removeSubscription(topic, sub.getClientId());
                continue;
            }
            if (qos.ordinal() > sub.getRequestedQos().ordinal()) {
                qos = sub.getRequestedQos();
            }

            ByteBuffer message = origMessage.duplicate();

            if (qos == AbstractMessage.QOSType.MOST_ONE && sub.isActive()) {
                //QoS 0
                sendPublish(sub.getClientId(), topic, qos, message, false);
            } else {
                //QoS 1 or 2
                //if the target subscription is not clean session and is not connected => store it
                if (!sub.isCleanSession() && !sub.isActive()) {
                    //clone the event with matching clientID
                    PublishEvent newPublishEvt = new PublishEvent(topic, qos, message, retain, sub.getClientId(), messageID);
                    m_storageService.storePublishForFuture(newPublishEvt);
                } else  {
                    //if QoS 2 then store it in temp memory
                    if (qos ==AbstractMessage.QOSType.EXACTLY_ONCE) {
                        String publishKey = String.format("%s%d", sub.getClientId(), messageID);
                        PublishEvent newPublishEvt = new PublishEvent(topic, qos, message, retain, sub.getClientId(), messageID);
                        m_storageService.addInFlight(newPublishEvt, publishKey);
                    }
                    //publish
                    if (sub.isActive()) {
                        sendPublish(sub.getClientId(), topic, qos, message, false);
                    }
                }
            }
        }
    }
151556
@JsTopic
	@WsDataService
	public Integer subscribe(@JsTopicName(prefix = Constants.Topic.SUBSCRIBERS) String topic, Session session) throws IllegalAccessException {
		return topicManager.registerTopicSession(topic, session);
	}
630953
public static void main(String[] args) throws ResponderConfigException {

    Responder responder = initialize(args);
    if (responder != null) {
      responder.run();
    }

  }
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();
	}
271707
public static void main(final String[] args) {
        new SpringApplicationBuilder(CasCommandLineShellApplication.class)
            .banner(new DefaultCasBanner())
            .bannerMode(Banner.Mode.CONSOLE)
            .logStartupInfo(true)
            .web(WebApplicationType.NONE)
            .run(args);
    }
467073
@Override
    public java.util.concurrent.Future<PublishResult> publishAsync(String topicArn, String message, String subject) {

        return publishAsync(new PublishRequest().withTopicArn(topicArn).withMessage(message).withSubject(subject));
    }
619507
public void setSubscribers(java.util.Collection<Subscriber> subscribers) {
        if (subscribers == null) {
            this.subscribers = null;
            return;
        }

        this.subscribers = new java.util.ArrayList<Subscriber>(subscribers);
    }