Beispiel #1
0
        public ITopologyBuilder GetTopologyBuilder()
        {
            TransactionalTopologyBuilder topologyBuilder = new TransactionalTopologyBuilder(typeof(HybridTopologyTx_javaSpout_csharpBolt).Name + DateTime.Now.ToString("yyyyMMddHHmmss"));

            // Demo how to use clojure code (in string) to initialize the constructor of Java Spout/Bolt
            JavaComponentConstructor constructor = JavaComponentConstructor.CreateFromClojureExpr("(microsoft.scp.example.HybridTopology.TxGenerator. 100 \"test\" nil)");

            topologyBuilder.SetJavaSpout(
                "generator",
                constructor,
                1);

            // Demo how to set a customized JSON Serializer to serialize a Java object (emitted by Java Spout) into JSON string
            // Here, fullname of the Java JSON Serializer class is required
            List <string> javaSerializerInfo = new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONSerializer"
            };

            topologyBuilder.SetBolt(
                "displayer",
                SCPTxBolt.SCP_TX_COMMIT_BOLT,
                TxDisplayer.Get,
                new Dictionary <string, List <string> >(),
                1).
            DeclareCustomizedJavaSerializer(javaSerializerInfo).
            shuffleGrouping("generator");

            topologyBuilder.SetTopologyConfig(new Dictionary <string, string>()
            {
                { "topology.kryo.register", "[\"[B\"]" }
            });

            return(topologyBuilder);
        }
        public ITopologyBuilder GetTopologyBuilder()
        {
            appConfig = new AppConfig();

            TopologyBuilder topologyBuilder = new TopologyBuilder(this.GetType().Name);

            // Set a customized JSON Deserializer to deserialize a C# object (emitted by C# Spout) into JSON string for Java to Deserialize
            // Here, fullname of the Java JSON Deserializer class is required followed by the Java types for each of the fields
            List <string> javaDeserializerInfo =
                new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONDeserializer", "java.lang.String"
            };

            topologyBuilder.SetSpout(
                typeof(EventGenerator).Name,
                EventGenerator.Get,
                new Dictionary <string, List <string> >()
            {
                { Constants.DEFAULT_STREAM_ID, new List <string>()
                  {
                      "Event"
                  } }
            },
                appConfig.EventHubPartitions,
                true
                ).
            DeclareCustomizedJavaDeserializer(javaDeserializerInfo);

            //We will use CreateFromClojureExpr method as we wish to pass in a complex Java object
            //The EventHubBolt takes a EventHubBoltConfig that we will create using clojure
            //NOTE: We need to escape the quotes for strings that need to be passes to clojure
            JavaComponentConstructor constructor =
                JavaComponentConstructor.CreateFromClojureExpr(
                    String.Format(@"(com.microsoft.eventhubs.bolt.EventHubBolt. (com.microsoft.eventhubs.bolt.EventHubBoltConfig. " +
                                  @"""{0}"" ""{1}"" ""{2}"" ""{3}"" ""{4}"" {5}))",
                                  appConfig.EventHubSharedAccessKeyName, appConfig.EventHubSharedAccessKey,
                                  appConfig.EventHubNamespace, appConfig.EventHubFqnAddress,
                                  appConfig.EventHubEntityPath, "true"));

            topologyBuilder.SetJavaBolt(
                "EventHubBolt",
                constructor,
                appConfig.EventHubPartitions
                ).
            shuffleGrouping(typeof(EventGenerator).Name);

            //Assuming a 4 'L' node cluster, we will have 16 worker slots available
            //We will half of those slots for this topology
            topologyBuilder.SetTopologyConfig(new Dictionary <string, string>()
            {
                { "topology.workers", "8" },
                { "topology.max.spout.pending", "1600" }
            });

            return(topologyBuilder);
        }
Beispiel #3
0
        /// <summary>
        /// Builds a topology that can be submitted to Storm on HDInsight
        /// </summary>
        /// <returns>A topology builder</returns>
        public ITopologyBuilder GetTopologyBuilder()
        {
            //The friendly name is 'EventHubWriter'
            TopologyBuilder topologyBuilder = new TopologyBuilder("EventHubWriter" + DateTime.Now.ToString("yyyyMMddHHmmss"));

            //Get the partition count
            int partitionCount = int.Parse(ConfigurationManager.AppSettings["EventHubPartitionCount"]);
            //Create a deserializer for JSON to java.lang.String
            //so that Java components can consume data emitted by
            //C# components
            List <string> javaDeserializerInfo =
                new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONDeserializer", "java.lang.String"
            };

            //Set the spout
            topologyBuilder.SetSpout(
                "Spout",
                Spout.Get,
                new Dictionary <string, List <string> >()
            {
                { Constants.DEFAULT_STREAM_ID, new List <string>()
                  {
                      "Event"
                  } }
            },
                partitionCount).                                     //Parallelism hint uses partition count
            DeclareCustomizedJavaDeserializer(javaDeserializerInfo); //Deserializer for the output stream

            //Create constructor for the Java bolt
            JavaComponentConstructor constructor =
                JavaComponentConstructor.CreateFromClojureExpr(
                    String.Format(@"(org.apache.storm.eventhubs.bolt.EventHubBolt. (org.apache.storm.eventhubs.bolt.EventHubBoltConfig. " +
                                  @"""{0}"" ""{1}"" ""{2}"" ""{3}"" ""{4}"" {5}))",
                                  ConfigurationManager.AppSettings["EventHubPolicyName"],
                                  ConfigurationManager.AppSettings["EventHubPolicyKey"],
                                  ConfigurationManager.AppSettings["EventHubNamespace"],
                                  "servicebus.windows.net", //suffix for servicebus fqdn
                                  ConfigurationManager.AppSettings["EventHubName"],
                                  "true"));

            topologyBuilder.SetJavaBolt(
                "EventHubBolt",
                constructor,
                partitionCount).      //Parallelism hint uses partition count
            shuffleGrouping("Spout"); //Consume data from spout

            StormConfig config = new StormConfig();

            config.setNumWorkers(1); //Set the number of workers
            topologyBuilder.SetTopologyConfig(config);

            return(topologyBuilder);
        }
Beispiel #4
0
        /// <summary>
        /// Builds a topology that can be submitted to Storm on HDInsight
        /// </summary>
        /// <returns>A topology builder</returns>
        public ITopologyBuilder GetTopologyBuilder()
        {
            // Friendly name of the topology
            TopologyBuilder topologyBuilder = new TopologyBuilder("EventHubWriter" + DateTime.Now.ToString("yyyyMMddHHmmss"));

            // Number of partitions in Event Hub. Used for parallelization.
            int partitionCount = int.Parse(ConfigurationManager.AppSettings["EventHubPartitionCount"]);

            // Deserializer used to deserialize JSON data from C# components to java.lang.string
            List <string> javaDeserializerInfo = new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONDeserializer", "java.lang.String"
            };

            // Spout that emits randomly generated JSON data
            topologyBuilder.SetSpout(
                "Spout",
                Spout.Get,
                new Dictionary <string, List <string> >()
            {
                { Constants.DEFAULT_STREAM_ID, new List <string>()
                  {
                      "event"
                  } }
            },
                partitionCount)
            .DeclareCustomizedJavaDeserializer(javaDeserializerInfo);

            // Java construcvtor for the Event Hub Bolt
            JavaComponentConstructor constructor = JavaComponentConstructor.CreateFromClojureExpr(
                String.Format(@"(org.apache.storm.eventhubs.bolt.EventHubBolt. (org.apache.storm.eventhubs.bolt.EventHubBoltConfig. " +
                              @"""{0}"" ""{1}"" ""{2}"" ""{3}"" ""{4}"" {5}))",
                              ConfigurationManager.AppSettings["EventHubPolicyName"],
                              ConfigurationManager.AppSettings["EventHubPolicyKey"],
                              ConfigurationManager.AppSettings["EventHubNamespace"],
                              "servicebus.windows.net",
                              ConfigurationManager.AppSettings["EventHubName"],
                              "true"));

            // Set the bolt to subscribe to data from the spout
            topologyBuilder.SetJavaBolt(
                "eventhubbolt",
                constructor,
                partitionCount)
            .shuffleGrouping("Spout");

            // Return the topology builder
            return(topologyBuilder);
        }
Beispiel #5
0
        public ITopologyBuilder GetTopologyBuilder()
        {
            TransactionalTopologyBuilder topologyBuilder = new TransactionalTopologyBuilder(typeof(HybridTopologyTx_csharpSpout_javaBolt).Name + DateTime.Now.ToString("yyyyMMddHHmmss"));

            // Demo how to set a customized JSON Deserializer to deserialize a JSON string into Java object (to send to a Java Bolt)
            // Here, fullname of the Java JSON Deserializer class and target deserialized class are required
            List <string> javaDeserializerInfo = new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONDeserializer", "microsoft.scp.example.HybridTopology.Person"
            };

            topologyBuilder.SetSpout(
                "generator",
                TxGenerator.Get,
                new Dictionary <string, List <string> >()
            {
                { Constants.DEFAULT_STREAM_ID, new List <string>()
                  {
                      "person"
                  } }
            },
                1,
                null).DeclareCustomizedJavaDeserializer(javaDeserializerInfo);

            // Demo how to use clojure code (in string) to initialize the constructor of Java Spout/Bolt
            JavaComponentConstructor constructor = JavaComponentConstructor.CreateFromClojureExpr("(microsoft.scp.example.HybridTopology.TxDisplayer. 100 \"test\" nil)");

            topologyBuilder.SetJavaBolt(
                "displayer",
                constructor,
                1).shuffleGrouping("generator");

            topologyBuilder.SetTopologyConfig(new Dictionary <string, string>()
            {
                { "topology.kryo.register", "[\"[B\"]" }
            });

            return(topologyBuilder);
        }
        public ITopologyBuilder GetTopologyBuilder()
        {
            appConfig = new AppConfig();

            TopologyBuilder topologyBuilder = new TopologyBuilder(this.GetType().Name);

            JavaComponentConstructor constructor =
                JavaComponentConstructor.CreateFromClojureExpr(
                    String.Format(@"(com.microsoft.eventhubs.spout.EventHubSpout. (com.microsoft.eventhubs.spout.EventHubSpoutConfig. " +
                                  @"""{0}"" ""{1}"" ""{2}"" ""{3}"" {4} """"))",
                                  appConfig.EventHubUsername, appConfig.EventHubPassword,
                                  appConfig.EventHubNamespace, appConfig.EventHubEntityPath,
                                  appConfig.EventHubPartitions));

            topologyBuilder.SetJavaSpout(
                "EventHubSpout",
                constructor,
                appConfig.EventHubPartitions);

            // Set a customized JSON Serializer to serialize a Java object (emitted by Java Spout) into JSON string
            // Here, fullname of the Java JSON Serializer class is required
            List <string> javaSerializerInfo = new List <string>()
            {
                "microsoft.scp.storm.multilang.CustomizedInteropJSONSerializer"
            };

            topologyBuilder.SetBolt(
                typeof(EventAggregator).Name,
                EventAggregator.Get,
                new Dictionary <string, List <string> >()
            {
                { Constants.DEFAULT_STREAM_ID, new List <string>()
                  {
                      "AggregationTimestamp", "PrimaryKey", "SecondaryKey", "AggregatedValue"
                  } }
            },
                appConfig.EventHubPartitions,
                true
                ).
            DeclareCustomizedJavaSerializer(javaSerializerInfo).
            shuffleGrouping("EventHubSpout");

            //You can also setup a Ranker bolt to maintain top N records

            /*
             * topologyBuilder.SetBolt(
             *      typeof(EventRanker).Name,
             *      EventRanker.Get,
             *      new Dictionary<string, List<string>>()
             *      {
             *          {Constants.DEFAULT_STREAM_ID, new List<string>(){ "AggregationTimestamp", "PrimaryKey", "SecondaryKey", "AggregatedValue" } }
             *      },
             *      appConfig.EventHubPartitions / 2
             *  ).
             *  fieldsGrouping(typeof(EventAggregator).Name, new List<int>() { 0, 1, 2 });
             */

            topologyBuilder.SetBolt(
                typeof(EventHBaseWriter).Name,
                EventHBaseWriter.Get,
                new Dictionary <string, List <string> >(),
                appConfig.EventHubPartitions / 4).
            fieldsGrouping(typeof(EventAggregator).Name, new List <int>()
            {
                0, 1, 2
            });

            //Assuming a 4 'Large' node cluster we will use half of the worker slots for this topology
            //The default JVM heap size for workers is 768m, we also increase that to 1024m
            //That helps the java spout have additional heap size at disposal.
            topologyBuilder.SetTopologyConfig(new Dictionary <string, string>()
            {
                { "topology.workers", "8" },
                { "topology.max.spout.pending", "1000" },
                { "topology.worker.childopts", @"""-Xmx1024m""" }
            });

            return(topologyBuilder);
        }