Skip to content

Commit fe91c8a

Browse files
committed
Tidying up and linking to the multithreaded origin tutorial
1 parent 846887c commit fe91c8a

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎readme.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The following tutorials demonstrate some StreamSets [Data Collector](http://gith
1616

1717
- [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.
1818

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+
1921
- [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.
2022

2123
- [Creating a Custom StreamSets Destination](tutorial-destination/readme.md) - Build a simple custom destination that writes batches of records to a webhook.

‎tutorial-multithreaded-origin/README.md‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
Creating a Custom StreamSets Origin which Supports Parallel Execution
1+
Creating a Custom Multithreaded StreamSets Origin
22
===================================
33

44
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!_
710
### What is a Streamsets Origin?
811
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.
912
### 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+
1115
The first step to do is to create a new custom stage project. From a command shell execute:
1216

1317
```
@@ -18,7 +22,9 @@ $MAVEN_HOME/bin/mvn archetype:generate -DarchetypeGroupId=com.streamsets \
1822

1923
During the execution of this command you will be asked for the groupId, artifactId and version for the project.
2024
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:
21-
[Origin project structure](https://github.com/streamsets/tutorials/blob/master/tutorial-origin/image_1.png)
25+
26+
![Origin project structure](../tutorial-origin/image_1.png)
27+
2228
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:
2329

2430
```
@@ -27,7 +33,7 @@ $MAVEN_HOME/bin/mvn eclipse:eclipse
2733
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.
2834
### Modifying the Origin Template Code
2935
#### 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```:
3137

3238
```java
3339
public abstract class SampleSource extends BasePushSource
@@ -37,19 +43,19 @@ You have then to override the *produce* method for the new parent class
3743
```java
3844
public void produce(Map<String, String> offsets, int maxBatchSize) throws StageException
3945
```
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```).
4147
#### Implementing the Thread Class
4248
You need to add the code for the class (it could be an inner one) that implements the ```java.lang.Runnable``` interface:
4349

4450
```java
4551
public class RecordGeneratorThread implements Runnable
4652
```
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:
4854

4955
```java
5056
RecordGeneratorThread(int threadId)
5157
```
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```:
5359

5460
```java
5561
BatchContext batchContext = getContext().startBatch();
@@ -72,7 +78,7 @@ and finally processed by the remainder of the pipeline:
7278
getContext().processBatch(batchContext);
7379
```
7480
#### 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:
7682

7783
```java
7884
@ConfigDef(

0 commit comments

Comments
 (0)