MuleSoft Integration Platform Basics: “Streamlining Data Integration: A Guide to Setting up Connectors and Network Sharing”- Part 2

Thinqloud Solutions
6 min readApr 3, 2024

--

This article has been prepared by our Salesforce Engineer, Atharva Toke, member of the Thinqloud Engineering team.

Welcome to the second part of the Mulesoft Integration series where we will be discussing all about MuleSoft basics. In this segment, we will start by exploring how to connect to databases, FTP folders and network folders.

  1. Setting up the FTP Connector.
  • Create a Mule Project:
  • Create a Mule Project: In Anypoint Studio, go to File > New > Mule Project.
  • Enter a name for your project and click Finish.
Creating Mule Project in Anypoint Studio
  • Add the FTP Connector to Your Project:
  • In the Mule Palette view, click on Search in Exchange.
  • Search for “FTP Connector” and select it.
  • Click Add and then Finish Or you can drag and drop the connector on Canvas.
FTP Connector List from Mule Palette

Configure a Source:

  • In the Mule Palette view, select “On New or Updated File” or “Scheduler” as the source.
  • Drag it onto the Studio canvas.
  • Specify the path and configure the FTP server host under the General tab.
  • Test the connection to ensure successful connectivity.

Add a Connector Operation to the Flow:

  • In the Mule Palette view, select “FTP” and choose the desired operation.
  • Drag the operation next to the source on the Studio canvas.

Configure a Global Element for the Connector:

  • Select the connector name in the Studio canvas.
  • Select the operation in the canvas and configure it by accessing global element configuration fields.
  • Specify connection information like host, port, username, password, etc., under the General tab.
  • Optionally set timeout configurations and reconnection strategies.

Read Files Using FTP Connector:

  • Search for “ftp” in the Mule Palette view and select the Read operation.
  • Drag it onto the Studio canvas.
  • Configure the operation by setting File Path, MIME Type, and Encoding under the General tab.

Save Changes and Run Application:

  • Save your changes and run the application to read files from the FTP server securely.

Code for the configuration-(pom.xml) {Alternative way to connect to FTP} (please adjust some parts from this snippet based on your needs)

<ftp:config name="FTP_Config" doc:name="FTP Config" doc:id="bcb2efd2-0e55-4ac2-90ef-a1282d17df97" >
<ftp:connection workingDir="ftpsql" host="176.46.26.203" username="FTP-Server" password="$esdcure#890" />
</ftp:config>

You can use the above XML code in the pom.xml file by just exchanging workingDir, host, username, password as per the corresponding requirements.

You an also check if the connection that we made with the FTP folder is working or not by clicking on the “Test Connection” button.

FTP Configuration
Test Connection Successful

2. Connecting to Database {MySQL Connector}

Create a Mule Project:

  • Create a Mule Project: In Anypoint Studio, go to File > New > Mule Project.
  • Enter a name for your project and click Finish.

Add the Database Connector to Your Project:

  • In the Mule Palette view, click on Search in Exchange.
  • Search for “Database Connector” and select it.
  • Click Add and then Finish Or you can drag and drop the connector on Canvas.
Database Connector list from Mule Palette
  • Add MySQL Connector Dependency:
  • In your Mule Canvas, navigate to the database connector and configuration with the MySQL Database, by clicking on the {+} icon.
  • Add the MySQL Connector (Maven) dependency by adding JDBC Driver:
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>

Configure Database Connection:

  • Enter the necessary connection details like host, port, database name, username, and password.

Test the Connection:

  • Run your application in Anypoint Studio to test the MySQL connection.
  • Verify that you can connect to the MySQL database and perform operations successfully.

Close the Connection:

  • Ensure that you close the MySQL connection after executing your queries to release resources properly.

Code for the configuration-(pom.xml) {Alternative way to connect to MySQL Database} (please adjust some parts from this snippet based on your needs)

<db:config name="Database_Config1" doc:name="Database Config" doc:id="8a8fd054-ba88-4f19-a96b-7625bbfeefd9" >
<db:my-sql-connection host="172.16.16.203" port="3306" user="root" password="M1cr0s0ft@123" database="mysql" />
</db:config>

By following these steps, you can create a seamless connection between your Mule application in Anypoint Studio and a MySQL database, enabling efficient data retrieval and manipulation.

3. Connecting to Database {PostgreSQL Connector}

  • Create a Mule Project:
  • Create a Mule Project:In Anypoint Studio, go to File > New > Mule Project.
  • Enter a name for your project and click Finish.
  • Add the Database Connector to Your Project:
  • In the Mule Palette view, click on Search in Exchange.
  • Search for “Database Connector” and select it.
  • Click Add and then Finish Or you can drag and drop the connector on Canvas.

Add PostgreSQL Connector Dependency:

  • In your Mule Canvas, navigate to the database connector and configuration with the PostgreSQL Database, by clicking on the {+} icon.
  • Add the PostgreSQL Connector(Maven) dependency by adding JDBC Driver:
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.2</version>
</dependency>

Configure Database Connection:

  • Enter the necessary connection details like:-
    - URL ⇒ jdbc:postgresql://176.18.16.208:5432/mulesoft_db
    - Driver Class Name ⇒ org.postgresql.Driver
    - User ⇒ As per Requirement
    - Passwords ⇒ As per Requirement

Test the Connection:

  • Run your application in Anypoint Studio to test the MySQL connection.
  • Verify that you can connect to the MySQL database and perform operations successfully.

Close the Connection:

  • Ensure that you close the MySQL connection after executing your queries to release resources properly.

Code for the configuration-(pom.xml) {Alternative way to connect to PostgreSQL Database}

<db:config name="Database_Config" doc:name="Database Config" doc:id="e234c8f8-eb2f-42b0-81b0-e4cacf774ceb" >
<db:generic-connection url="jdbc:postgresql://176.16.18.208:5432/mulesoft_db" driverClassName="org.postgresql.Driver" user="postgres" password="postgres" />
</db:config>
PostgreSQL Database Configuration
Test Connection Successful

By following these steps, you can create a seamless connection between your Mule application in Anypoint Studio and a PostgreSQL Database, enabling efficient data retrieval and manipulation.

4. Setting up Internal Network Shared Folder and Network Connector.

Setting up network Folder
  • Add appropriate Network File Folder & Advanced Sharing Settings so that the network folder should be visible in the server network.
  • To configure the network folder, drag and drop the necessary elements. When connecting to the network server and reading files from the server, the following elements are commonly used => Read | On New or Updated File
  • Track down the path of the working directory.

Code for the configuration-(pom.xml) {Alternative way to connect to Network Folder}

<file:config name="File_Config_network" doc:name="File Config" doc:id="6ea7add3-eeed-459b-abab-96338d1e91b9" >
<file:connection workingDir="\\DESKTOP-26C4JEJ\ftpsql" />
</file:config>
Results of the Network Connection Which is Connected to the Local System

Coming Up Next….

This blog post has continued the exciting journey to explore the Mulesoft Integration platform and detailed the MuleSoft basic setup and configuration steps. Stay tuned for a wealth of engaging topics and insightful discussions on the MuleSoft Integration series in the upcoming blogs!

  • MuleSoft Integration Platform Basics: “Efficient Data Processing: Strategies for Handling CSV, Excel and JSON Files” — Part 3
  • MuleSoft Integration Platform Basics: “Optimizing Workflows: From File Reading to JSON Conversion and Order Transaction Checks” — Part 4
  • MuleSoft Integration Platform Basics: “Enhancing Monitoring and Logging: Error Handling, Log Saving” — Part 5
  • MuleSoft Integration Platform Basics: “Empowering Connectivity: API Gateway Setup and Database Invoicing with Fast API Integration and Real-Time Project Monitoring on CloudHub” — Part 6
  • Access Part I of the series here

Follow us & Connect at:-

LinkedIn: - https://in.linkedin.com/company/thinqloud

medium.com:- Thinqloud Solutions — Medium

Company Site:- https://www.thinqloud.com/

Please let us know if you have any suggestions, comments or just general feedback for us!

--

--