Skip to content

Commit f014ae7

Browse files
authored
Merge pull request #55 from anuruddhal/main
Add file integration sample
2 parents c78cf5a + b59d18c commit f014ae7

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed
Loading
Loading
Loading
Loading

en/docs/learn/file-integration.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# File integration
2+
3+
In this section, we will learn how to create a file integration using the Ballerina Integrator. The integration will listen to events in a directory and will be triggered when an file related event occurs.
4+
5+
### Step 1: Create a new integration project.
6+
1. Click on the Ballerina Integrator icon on the sidebar.
7+
2. Click on the **`Create New Integration`** button.
8+
3. Enter the project name as `FileIntegration`.
9+
4. Select Project Directory and click on the **`Select Location`** button.
10+
5. Click on the **`Create New Integration`** button to create the integration project.
11+
12+
### Step 2: Create an Directory service.
13+
1. In the design view, click on the **`Add Artifact`** button.
14+
2. Select **`Directory Service`** under the **`File Integration`** category.
15+
3. Enter the listener name as `directoryListener`.
16+
4. Enter the path to the directory you want to monitor. For example, `"/home/user/Downloads"`.
17+
5. Click on the **`Next`** button to create the directory service.
18+
6. Keep the default listener in the **`Listener Configuration`** window and click on the **`Create`** button to create the directory service.
19+
<a href="{{base_path}}/assets/img/file-integration/directory-service.gif"><img src="{{base_path}}/assets/img/file-integration/directory-service.gif" alt="Create Directory Service" width="70%"></a>
20+
21+
### Step 3: Configure file event resources
22+
1. Navigate to the `directoryListener` service under the **`Entry Points`** section and click on the **`+Function`** button.
23+
2. Select **`onCreate`** from **`Available Functions`** dropdown and click on the **`Save`** button.
24+
3. Click on the **`onCreate`** function to navigate to the function implementation designer view.
25+
4. Click on **`+`** and select **`Log Info`** from the node panel under **`Logging`** category.
26+
5. Add the log message as `"File created "+ event.name` in the **`Msg`** field.
27+
6. Click on the **`Save`** button to add the log action to the function.
28+
<a href="{{base_path}}/assets/img/file-integration/add-resource.gif"><img src="{{base_path}}/assets/img/file-integration/add-resource.gif" alt="onCreate Function" width="70%"></a>
29+
7. Repeat the above steps to add the **`onDelete`** and **`onModify`** functions to the service.
30+
8. Add the log message as `"File deleted "+ event.name` in the **`Msg`** field for the **`onDelete`** function.
31+
9. Add the log message as `"File modified "+ event.name` in the **`Msg`** field for the **`onModify`** function.
32+
10. The final service will look like this:
33+
<a href="{{base_path}}/assets/img/file-integration/final-service.png"><img src="{{base_path}}/assets/img/file-integration/final-service.png" alt="Final Service" width="70%"></a>
34+
35+
### Step 4: Run the integration
36+
1. Click on the **`Run`** button in the top-right corner to run the integration.
37+
2. The integration will start listening to the events in the directory specified in step 2.
38+
3. Create a new file in the directory to trigger the **`onCreate`** event.
39+
4. Modify the file to trigger the **`onModify`** event.
40+
5. Delete the file to trigger the **`onDelete`** event.
41+
6. The log messages will be displayed in the console.
42+
<a href="{{base_path}}/assets/img/file-integration/run-integration.png"><img src="{{base_path}}/assets/img/file-integration/run-integration.png" alt="Run Integration" width="70%"></a>

en/mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ nav:
8282
- AI-assisted integration: learn/integration-ai.md
8383
- Data mapping: learn/data-mapping.md
8484
- Natural functions: learn/natural-functions.md
85+
- File integration: learn/file-integration.md
8586
- Deploy:
8687
- Deploy on a VM: deploy/jar.md
8788
- Deploy with Docker: deploy/docker.md

0 commit comments

Comments
 (0)