17
17
package com .weightwatchers .reactive .kinesis .stream
18
18
19
19
import akka .{Done , NotUsed }
20
- import akka .actor .{ActorSystem , Props }
20
+ import akka .actor .{ActorRef , ActorSystem , Props }
21
21
import akka .stream .scaladsl .{Sink , Source }
22
22
import com .amazonaws .auth .AWSCredentialsProvider
23
23
import com .typesafe .config .Config
24
24
import com .typesafe .scalalogging .LazyLogging
25
+ import com .weightwatchers .reactive .kinesis .consumer .{ConsumerService , KinesisConsumer }
25
26
import com .weightwatchers .reactive .kinesis .consumer .KinesisConsumer .ConsumerConf
26
27
import com .weightwatchers .reactive .kinesis .models .{ConsumerEvent , ProducerEvent }
27
28
import com .weightwatchers .reactive .kinesis .producer .{KinesisProducerActor , ProducerConf }
@@ -33,6 +34,23 @@ import scala.concurrent.Future
33
34
*/
34
35
object Kinesis extends LazyLogging {
35
36
37
+ /**
38
+ * Create a source, that provides KinesisEvents.
39
+ * Please note: every KinesisEvent has to be committed during the user flow!
40
+ * Uncommitted events will be retransmitted after a timeout.
41
+ *
42
+ * @param consumerConf the configuration to connect to Kinesis.
43
+ * @param createConsumer factory function to create ConsumerService from eventProcessor ActorRef.
44
+ * @param system the actor system.
45
+ * @return A source of KinesisEvent objects.
46
+ */
47
+ def source (
48
+ consumerConf : ConsumerConf ,
49
+ createConsumer : ActorRef => ConsumerService
50
+ )(implicit system : ActorSystem ): Source [CommittableEvent [ConsumerEvent ], NotUsed ] = {
51
+ Source .fromGraph(new KinesisSourceGraphStage (consumerConf, createConsumer, system))
52
+ }
53
+
36
54
/**
37
55
* Create a source, that provides KinesisEvents.
38
56
* Please note: every KinesisEvent has to be committed during the user flow!
@@ -45,7 +63,7 @@ object Kinesis extends LazyLogging {
45
63
def source (
46
64
consumerConf : ConsumerConf
47
65
)(implicit system : ActorSystem ): Source [CommittableEvent [ConsumerEvent ], NotUsed ] = {
48
- Source .fromGraph( new KinesisSourceGraphStage (consumerConf, system))
66
+ source(consumerConf, KinesisConsumer (consumerConf, _ , system))
49
67
}
50
68
51
69
/**
@@ -69,12 +87,69 @@ object Kinesis extends LazyLogging {
69
87
* @param system the actor system to use.
70
88
* @return A source of KinesisEvent objects.
71
89
*/
72
- def source (consumerName : String , inConfig : String = " kinesis " )(
90
+ def source (consumerName : String , inConfig : String )(
73
91
implicit system : ActorSystem
74
92
): Source [CommittableEvent [ConsumerEvent ], NotUsed ] = {
75
93
source(ConsumerConf (system.settings.config.getConfig(inConfig), consumerName))
76
94
}
77
95
96
+ /**
97
+ * Create a source by using the actor system configuration, that provides KinesisEvents.
98
+ * Please note: every KinesisEvent has to be committed during the user flow!
99
+ * Uncommitted events will be retransmitted after a timeout.
100
+ *
101
+ * A minimal application conf file should look like this:
102
+ * {{{
103
+ * kinesis {
104
+ * application-name = "SampleService"
105
+ * consumer-name {
106
+ * stream-name = "sample-stream"
107
+ * }
108
+ * }
109
+ * }}}
110
+ * See kinesis reference.conf for a list of all available config options.
111
+ *
112
+ * @param consumerName the name of the consumer in the application.conf.
113
+ * @param system the actor system to use.
114
+ * @return A source of KinesisEvent objects.
115
+ */
116
+ def source (consumerName : String )(
117
+ implicit system : ActorSystem
118
+ ): Source [CommittableEvent [ConsumerEvent ], NotUsed ] = {
119
+ source(consumerName, " kinesis" )
120
+ }
121
+
122
+ /**
123
+ * Create a source by using the actor system configuration, that provides KinesisEvents.
124
+ * Please note: every KinesisEvent has to be committed during the user flow!
125
+ * Uncommitted events will be retransmitted after a timeout.
126
+ *
127
+ * A minimal application conf file should look like this:
128
+ * {{{
129
+ * kinesis {
130
+ * application-name = "SampleService"
131
+ * consumer-name {
132
+ * stream-name = "sample-stream"
133
+ * }
134
+ * }
135
+ * }}}
136
+ * See kinesis reference.conf for a list of all available config options.
137
+ *
138
+ * @param consumerName the name of the consumer in the application.conf.
139
+ * @param createConsumer factory function to create ConsumerService from eventProcessor ActorRef.
140
+ * @param inConfig the name of the sub-config for kinesis.
141
+ * @param system the actor system to use.
142
+ * @return A source of KinesisEvent objects.
143
+ */
144
+ def source (
145
+ consumerName : String ,
146
+ createConsumer : (ConsumerConf , ActorRef ) => ConsumerService ,
147
+ inConfig : String = " kinesis"
148
+ )(implicit system : ActorSystem ): Source [CommittableEvent [ConsumerEvent ], NotUsed ] = {
149
+ val consumerConf = ConsumerConf (system.settings.config.getConfig(inConfig), consumerName)
150
+ source(consumerConf, createConsumer(consumerConf, _))
151
+ }
152
+
78
153
/**
79
154
* Create a Sink that accepts ProducerEvents, which get published to Kinesis.
80
155
*
@@ -91,9 +166,10 @@ object Kinesis extends LazyLogging {
91
166
* @param system the actor system.
92
167
* @return A sink that accepts ProducerEvents.
93
168
*/
94
- def sink (props : => Props , maxOutStanding : Int )(
95
- implicit system : ActorSystem
96
- ): Sink [ProducerEvent , Future [Done ]] = {
169
+ def sink (
170
+ props : => Props ,
171
+ maxOutStanding : Int
172
+ )(implicit system : ActorSystem ): Sink [ProducerEvent , Future [Done ]] = {
97
173
Sink .fromGraph(new KinesisSinkGraphStage (props, maxOutStanding, system))
98
174
}
99
175
@@ -143,11 +219,11 @@ object Kinesis extends LazyLogging {
143
219
* @param system the actor system.
144
220
* @return A sink that accepts ProducerEvents.
145
221
*/
146
- def sink (kinesisConfig : Config ,
147
- producerName : String ,
148
- credentialsProvider : Option [ AWSCredentialsProvider ])(
149
- implicit system : ActorSystem
150
- ): Sink [ProducerEvent , Future [Done ]] = {
222
+ def sink (
223
+ kinesisConfig : Config ,
224
+ producerName : String ,
225
+ credentialsProvider : Option [ AWSCredentialsProvider ]
226
+ )( implicit system : ActorSystem ) : Sink [ProducerEvent , Future [Done ]] = {
151
227
sink(
152
228
ProducerConf (kinesisConfig, producerName, credentialsProvider)
153
229
)
@@ -183,11 +259,11 @@ object Kinesis extends LazyLogging {
183
259
* @param system the actor system.
184
260
* @return A sink that accepts ProducerEvents.
185
261
*/
186
- def sink (producerName : String ,
187
- inConfig : String = " kinesis " ,
188
- credentialsProvider : Option [ AWSCredentialsProvider ] = None )(
189
- implicit system : ActorSystem
190
- ): Sink [ProducerEvent , Future [Done ]] = {
262
+ def sink (
263
+ producerName : String ,
264
+ inConfig : String = " kinesis " ,
265
+ credentialsProvider : Option [ AWSCredentialsProvider ] = None
266
+ )( implicit system : ActorSystem ) : Sink [ProducerEvent , Future [Done ]] = {
191
267
sink(system.settings.config.getConfig(inConfig), producerName, credentialsProvider)
192
268
}
193
269
}
0 commit comments