60 likes | 63 Views
When it passes from source to destination, most integrations involve a shift to the data structure. Within the Mule app, you can use the Transform Message component's drag-and-drop interface to map data from one field or format to another, or you can manually write mappings within Data Weave scripts. In Studio or Design Center, you usually create Mule apps, but you can also write Mule app configurations in XML by hand. You are using Studio for this.
E N D
Explain Mule App Development When it passes from source to destination, most integrations involve a shift to the data structure. Within the Mule app, you can use the Transform Message component's drag-and-drop interface to map data from one field or format to another, or you can manually write mappings within Data Weave scripts. In Studio or Design Center, you usually create Mule apps, but you can also write Mule app configurations in XML by hand. You are using Studio for this. You can build a project and describe the transition mapping from the API into a different structure and protocol using a small data set and a training API available on Exchange. Drag-n-drop will be used and you will also see the Data Weave code that describes the transformation. You'll be able to build your data mappings after completing this. Pre-Requirements MuleSoft recommends completing a few setup tasks to allow you to concentrate on a data mapping workflow. This is the paradigm that we'll transform. Download and have AnyPoint Studio mounted. If you don't have one, build a trial AnyPoint Platform account. Choose a client for the REST API, such as Postman or Advanced REST. Step One: Build a Project Mule 4 Build the project that your Mule app would include. Open the AnyPoint Studio and choose File > New > Project Mule. Configure dw-4-flights-ws as the project name. Leave all other defaults, and to build the project, select Finish. Look in the Package Explorer window when you're finished, to see the contents of your new project.
Step Two: Build a Mule 4 App and Set-Up We'll now add the elements needed to fetch data from an API. Then use Data Weave to turn it into a different structure. To listen to the American Flights API, add an HTTP listener operation. Select HTTP to show HTTP operations in the Mule Palette and drag the listener operation onto the canvas. Open the project file dw-4-flights-ws.xml in the src/main/mule folder in Package Explorer if you can't see something in the Mule Palette. To view its Properties tab, double-click the Listener operation and click the green plus sign to add a new configuration. In the Config HTTP Listener dialog, add the following values. Host: 0.0.0.0 0.0.0.0 Port: 8081 Port: To save these changes and close the dialog, click OK. Adjust the Path: to /flights area in the General tab for the Listener. Your adjustment is saved automatically. Rapid start Route Select Add Modules in the Mule Palette to display a list of modules and connectors, and drag the Database Connector to the left of the Mule Palette. You may be asked for a version to pick. Select the most current edition. Add db11 quickstart to runtime quickstart You can see the activities now that the Database connector is in the Mule Palette. Drag Operation Pick into the flow. Add db22 quickstart to runtime quickstart
Let's configure the database operation to listen to answers from the MySQL database sample of MuleSoft. To show its properties, click the Select Operator tab, and then click the add button (green cross) to open the Database Config dialog. In the dialog, select or type Mule's sample database values. ●Link: MySQL Connection to MySQL Connection ●Mudb.learn.mulesoft.com Host: ●Port: 3306 Port: ●Customer: mule ●Your password: mule ●Database: Education Values of runtime fast start DB values Select Configure > Add Maven Dependence while still in the Database Config dialog. In the Select a Maven dependency dialog, in the Search Maven Central search area, enter MySQL-. From the items shown, pick MySQL: MySQL-connector-java. To return to the Database Config dialog, click Finish. RUNTIME RapidStart DB Driver An effective Test Link message should be sent to you. Go back over the steps if you do not, and look for mistakes. To return to the Database Config dialog, click OK. Build a question from the Training: American Flights API that returns all flights. If it is not already open, to show its property tab, click the Select operation. In the question field, add a selection statement: Pick * FROM American. Your alterations are saved automatically. Select Question for Mruntime Quickstart Run the project to validate the setup so far. You can right-click and select Run Project dw-4-flights- ws from the canvas where the flow is described. Send a request from the client to http://localhost:8081/flights/. The application returns a 500 Server Error message at this point because it is unable to process the data obtained from the American Flights API query. This error is resolved when you add a Transform feature to the flow during the next training section. RUNTIME Fast start Object Now that the app is set up, it's time for some data to be converted into JSON so that a service that requires JSON can consume it. To avoid unintentionally creating an orphan process that could clog the port listed in your code, leave the Mule app running. Step Three: Build a Data Weave Data Transformation and evaluate it
Now that we have a Mule app that works and listens to the Training: American Flights API, we're going to add a Transform Message portion and use the drag-n-drop interface of Data Weave to define a transformation from a Mule object to a JSON object. Pick the Core in the Mule Palette and find the Transform Message variable. Add transform to runtime quickstart Drag and drop the Transform Message into the canvas to the right of the Pick process. MRUNTIME Faststart Canvas To show the graphical view and the source code view, click the Transform Message link. Mruntime quickstart dw blank palette Dw blank palette A schematic view of the metadata systems for input and output is on the left side. Lines and node points in the middle are defined by the mapping between them. A code view of the same structures and mapping is on the right side. The view of the code and the graphical views remain synchronized. Change the output form in line 2 from application/java to application/JSON in the code view, and replace brackets with the payload on lines 4 and 5. MRUNTIME Faststart DW Palette To redeploy the project, Save the update. By submitting a GET request to your http://localhost:8081/flights. REST client, evaluate this change: GET Quickstart MRUNTIME json11 You have converted a Mule object into JSON with only two words in a Data Weave script. We can now map the current API data to a data structure based on an instance we have. This example shows how the data from training needs to be consumed by a second service: American Flights API. Select Define metadata in the Transform Message Output panel to open the Select Metadata Style dialog. To open the Build New Form dialog, select Add. Enter American Flights Json and choose Type Build. Mruntime QuickStart Empty Form Empty Type. Set the type to JSON in the Pick metadata type dialog. Shift Schema to Example in the drop-down under Form. Copy and paste the file below and save it to your local device or environment. Please name the American-flights-example.json file. [{ "ID": 1, 1, "ID":
"Code": "ER38sd",, "ER38sd", Price"price"price DepartureDate"departureDate"2016/03/20"2016/03/20"DepartureDate Origin"origin"MUA"MUA"Origin destination"destination"SFO"SFO"SFO EmptySeats"emptySeats"EmptySeats Plane"plane"plane Type": "Boeing 737", "Type";" "totalSeats": 150 Seats: 150 } }, { { ID"ID"ID "code": "ER45if", "ER45if"; Price"price"Price departureDate"departureDate"2016/02/11"2016/02/11"2016/02/11 Origin"origin"MUA"MUA"Origin Destination"destination"LAX"LAX"Destination EmptySeats"emptySeats"EmptySeats Plane"plane"plane Type": "Boeing 777", "Type";" TotalSeats"totalSeats"TotalSeats } }]
Conclusion You're able to start scripting in the Data Weave language now that you have succeeded in transforming data. This is from Mule object to JSON, and from one data structure to another. You can learn more about this app development through MuleSoft online training.