-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathEventHubAggregatorToHBaseTopology.cs
195 lines (171 loc) · 8.44 KB
/
EventHubAggregatorToHBaseTopology.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using EventHubAggregatorToHBaseTopology.Bolts;
using EventHubAggregatorToHBaseTopology.Common;
using Microsoft.SCP;
using Microsoft.SCP.Topology;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace EventHubAggregatorToHBaseTopology
{
//IMPORTANT NOTE: All the logs from SCP.Net go into %STORM_HOME%\logs\scp directory on the respective worker nodes where the task is running
//Each log from Storm & SCP.Net is also written into a "hadoopservicelog" table in your storage account
//You can increase the readability of your logs by adding identifiers in your log messages
/// <summary>
/// A hybrid topology that generates a event in C# and uses Java bolt to write into EventHub
/// </summary>
class EventHubSenderHybridTopology : TopologyDescriptor
{
AppConfig appConfig;
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", appConfig.EventHubPartitions.ToString()},
{"topology.max.spout.pending","4096"}
});
return topologyBuilder;
}
}
/// <summary>
/// This is an example of using a pure C# topology to generate and sending events to EventHub
/// </summary>
class EventHubSenderCSharpTopology : TopologyDescriptor
{
AppConfig appConfig;
public ITopologyBuilder GetTopologyBuilder()
{
appConfig = new AppConfig();
TopologyBuilder topologyBuilder = new TopologyBuilder(this.GetType().Name);
topologyBuilder.SetSpout(
typeof(EventGenerator).Name,
EventGenerator.Get,
new Dictionary<string, List<string>>()
{
{Constants.DEFAULT_STREAM_ID, new List<string>(){"Event"}}
},
appConfig.EventHubPartitions
);
topologyBuilder.SetBolt(
typeof(EventHubWriter).Name,
EventHubWriter.Get,
new Dictionary<string, List<string>>(),
appConfig.EventHubPartitions
).
shuffleGrouping(typeof(EventGenerator).Name);
var topologyConfig = new StormConfig();
topologyConfig.setNumWorkers(appConfig.EventHubPartitions);
topologyConfig.setMaxSpoutPending(4096);
topologyBuilder.SetTopologyConfig(topologyConfig);
return topologyBuilder;
}
}
/// <summary>
/// This is our main topology that fetches the Events from EventHub
/// And aggregates them each minute on PrimaryKey/Secondary Key
/// You can choose to deploy multiple of such topologies to calculate different dimensions of data
/// Or add more bolts within same topology by switching PrimaryKey & SecondaryKey values
/// </summary>
[Active(true)]
class EventHubAggregatorToHBaseHybridTopology : TopologyDescriptor
{
AppConfig appConfig;
public ITopologyBuilder GetTopologyBuilder()
{
appConfig = new AppConfig();
TopologyBuilder topologyBuilder = new TopologyBuilder(this.GetType().Name);
topologyBuilder.SetEventHubSpout(
"EventHubSpout",
new EventHubSpoutConfig(
appConfig.EventHubSharedAccessKeyName,
appConfig.EventHubSharedAccessKey,
appConfig.EventHubNamespace,
appConfig.EventHubEntityPath,
appConfig.EventHubPartitions),
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.
var topologyConfig = new StormConfig();
topologyConfig.setNumWorkers(appConfig.EventHubPartitions);
topologyConfig.setMaxSpoutPending(4096);
topologyConfig.setWorkerChildOps("-Xmx1024m");
topologyBuilder.SetTopologyConfig(topologyConfig);
return topologyBuilder;
}
}
}