You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fe91c8a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: readme.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@ The following tutorials demonstrate some StreamSets [Data Collector](http://gith
16
16
17
17
-[Creating a Custom StreamSets Origin](tutorial-origin/readme.md) - Build a simple custom origin that reads a Git repository's commit log and produces the corresponding records.
18
18
19
+
-[Creating a Custom Multithreaded StreamSets Origin](tutorial-origin/readme.md) - A more advanced tutorial focusing on building an origin that supports parallel execution, so the pipeline can run in multiple threads.
20
+
19
21
-[Creating a Custom StreamSets Processor](tutorial-processor/readme.md) - Build a simple custom processor that reads metadata tags from image files and writes them to the records as fields.
20
22
21
23
-[Creating a Custom StreamSets Destination](tutorial-destination/readme.md) - Build a simple custom destination that writes batches of records to a webhook.
Copy file name to clipboardExpand all lines: tutorial-multithreaded-origin/README.md
+16-10Lines changed: 16 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,17 @@
1
-
Creating a Custom StreamSets Origin which Supports Parallel Execution
1
+
Creating a Custom Multithreaded StreamSets Origin
2
2
===================================
3
3
4
4
In [SDC](https://streamsets.com/products/sdc/) a multithreaded pipeline is a pipeline having an origin that supports parallel execution, so the pipeline can run in multiple threads. This tutorial explains how to get started writing your own custom Streamsets origin that supports parallel execution.
5
-
This tutorial completes the excellent [one](https://github.com/streamsets/tutorials/tree/master/tutorial-origin) by Pat Patterson available in the official SDC GitHub repository, which covers the creation process for a single threaded origin only. I highly recommend to follow that tutorial before starting with this one.
6
-
This tutorial refers to the SDC version 2.4.0.0, but the process should apply to newer versions as well.
5
+
6
+
This tutorial complements the [basic custom origin tutorial](https://github.com/streamsets/tutorials/tree/master/tutorial-origin), which covers the creation of a single threaded origin. You should complete that tutorial before starting on this one.
7
+
This tutorial refers to SDC version 2.4.0.0, but the process should apply to newer versions as well.
8
+
9
+
_Many thanks to Guglielmo Iozzia for contributing this tutorial!_
7
10
### What is a Streamsets Origin?
8
11
In SDC an origin stage represents the source of data for a pipeline. An origin reads data from some source, producing records to be consumed by the remainder of the pipeline. Several origins are currently available in the SDC libraries and they cover the most popular data sources, but it is possible any way to implement custom origins through the Data Collector APIs.
9
12
### Creating and Building an Origin Template
10
-
The process to create an origin template is the same described in Pat's tutorial. It requires [Apache Maven](https://maven.apache.org/).
13
+
The process to create an origin template is the same as described in the basic custom origin tutorial. It requires [Apache Maven](https://maven.apache.org/).
14
+
11
15
The first step to do is to create a new custom stage project. From a command shell execute:
During the execution of this command you will be asked for the groupId, artifactId and version for the project.
20
24
Maven generates a template project starting from the archetype in a directory which name is the provided artifactId. This is the structure for a newly created project:
Through Maven you can then add the files for the project to be imported in your favourite IDE. For Eclipse, move to the root folder of the project and then execute:
Maven creates the template files also to implement a custom destination, a custom processor and a custom executor in the *destination*, *executor* and *processor* packages: you can delete them all because the goal here is to implement a new origin only.
28
34
### Modifying the Origin Template Code
29
35
#### Extending the Proper Parent Class
30
-
The template code contains a class called ```SampleSource.java``` which extends the SDC ```BaseSource``` abstract class. The first change to do is to make the SampleSource class to extend ```com.streamsets.pipeline.api.base.BasePushSource```:
36
+
The template code contains a class called ```SampleSource.java``` which extends the SDC ```BaseSource``` abstract class. The first change to do is to make the SampleSource class extend ```com.streamsets.pipeline.api.base.BasePushSource```:
@@ -37,19 +43,19 @@ You have then to override the *produce* method for the new parent class
37
43
```java
38
44
public void produce(Map<String, String> offsets, int maxBatchSize) throws StageException
39
45
```
40
-
As you can see from its signature, this time there is of course no single offset, but a Map of offsets and no ```BatchMaker``` argument (because any thread has to start and manage its own ```BatchContext```).
46
+
As you can see from its signature, this time there is no single offset, but a Map of offsets and no ```BatchMaker``` argument (because any thread has to start and manage its own ```BatchContext```).
41
47
#### Implementing the ThreadClass
42
48
You need to add the code for the class (it could be an inner one) that implements the ```java.lang.Runnable``` interface:
43
49
44
50
```java
45
51
public class RecordGeneratorThread implements Runnable
46
52
```
47
-
Implement a constructor for it. In this example we are going to implement just one expecting a single argument, an integer to identify at runtime any single thread instance:
53
+
Implement a constructor for it. In this example we are going to implement just one constructor, expecting a single argument: an integer to identify at runtime any single thread instance:
48
54
49
55
```java
50
56
RecordGeneratorThread(int threadId)
51
57
```
52
-
The action is in the overriden *run* method. There you need to start a ```com.streamsets.pipeline.api.BatchContext```:
58
+
The action is in the overridden *run* method. There you need to start a ```com.streamsets.pipeline.api.BatchContext```:
@@ -72,7 +78,7 @@ and finally processed by the remainder of the pipeline:
72
78
getContext().processBatch(batchContext);
73
79
```
74
80
#### Thread Configuration
75
-
In order to allow the set up of the number of threads to issue at each pipeline run, you can add a configuration parameter to the ```SampleDSource.java``` class:
81
+
In order to allow setup of the number of threads to start at each pipeline run, you can add a configuration parameter to the ```SampleDSource.java``` class:
0 commit comments