001/* 002# Licensed Materials - Property of IBM 003# Copyright IBM Corp. 2015 004 */ 005package topic; 006 007import com.ibm.streamsx.topology.TStream; 008import com.ibm.streamsx.topology.Topology; 009import com.ibm.streamsx.topology.context.StreamsContextFactory; 010import com.ibm.streamsx.topology.tuple.BeaconTuple; 011 012/** 013 * Application which subscribes to a topic. 014 * 015 * @see PublishBeacon Sample application that 016 * publishes a topic 017 * @see <a href="../../../spldoc/html/tk$com.ibm.streamsx.topology/ns$com.ibm.streamsx.topology.topic$1.html">Integration with SPL applications</a> 018 */ 019public class SubscribeBeacon { 020 021 /** 022 * Submit this application which subscribes to a topic. 023 * @param args Command line arguments, accepts a single optional topic name. 024 * @throws Exception Error running the application 025 */ 026 public static void main(String[] args) throws Exception { 027 String topic = "/beacon"; 028 String type = "DISTRIBUTED"; 029 030 if (args.length >= 1) 031 topic = "/" + args[0]; 032 if (args.length == 2) 033 type = args[1]; 034 035 036 Topology topology = new Topology("SubscribeBeacon"); 037 038 TStream<BeaconTuple> beacon = topology.subscribe(topic, 039 BeaconTuple.class); 040 beacon.print(); 041 042 StreamsContextFactory.getStreamsContext(type) 043 .submit(topology); 044 } 045}