Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 5. Implement an AMQ to REST API sample integration
This sample integration connects to an AMQ broker to obtain item delivery records for a hypothetical enterprise. The integration then executes a custom step that operates on the records to identify any items that were damaged when they were received. After a simple data mapping, the integration connects to a REST API to obtain and provide contact information for vendors of damaged items.
The other sample integrations use connectors and data operations that are built into Ignite. This integration also does that, but in addition, it provides instructions for customizing and extending Ignite by leading you through the procedures for:
- Adding a custom data operation by uploading an extension.
- Adding a custom REST API client connector by uploading a Swagger file.
Ignite provides the extension file and the Swagger file.
To implement the AMQ to REST API sample integration, the main steps are:
- Section 5.1, “Create an AMQ connection”
- Section 5.2, “Make a custom step available”
- Section 5.3, “Create a REST API connector”
- Section 5.4, “Upload the To Do app icon”
- Section 5.5, “Create a REST API connection”
- Section 5.6, “Create and deploy AMQ to REST API sample integration”
- Section 5.7, “Confirm that the AMQ to REST API integration works”
- Section 5.8, “Clean up your integration”
5.1. Create an AMQ connection Link kopierenLink in die Zwischenablage kopiert!
The AMQ to REST API sample integration starts by connecting to an AMQ broker that is provided in your OpenShift project. Before you start to create the integration itself, you must:
5.1.1. Start the provided AMQ broker Link kopierenLink in die Zwischenablage kopiert!
To start the AMQ broker:
- In a browser, go to the OpenShift Web Console at https://console.fuse-ignite.openshift.com/console/. Your installation of Ignite runs on OpenShift Online.
-
In the console, click the name of your Ignite project, which is something like
proj123456
. - In the Overview page, scroll down to Other Resources to see the provided AMQ broker.
- To the left of broker-amq, #1, click the caret to display more information.
- In the additional information, all the way to the right, click the up caret to scale up to running 1 pod. This starts the AMQ broker.
5.1.2. Create a connection to that AMQ broker Link kopierenLink in die Zwischenablage kopiert!
To create a connection to the AMQ broker that is running in your Fuse Online project in OpenShift:
- In Ignite, in the left panel, click Connections to display any available connections.
- In the upper right, click Create Connection to display Ignite connectors.
- Click the AMQ connector.
Configure the connection by entering:
-
In the Broker URL field, enter
tcp://broker-amq-tcp:61616
as the location to obtain data from. -
In the Username field, enter
amq
as the user name for the account that accesses this AMQ broker. -
In the Password field, enter
topSecret
as the password for the account that accesses this AMQ broker. - Leave the other fields blank.
-
In the Broker URL field, enter
- Click Validate. Ignite immediately tries to validate the connection and displays a message that indicates whether validation is successful. If validation fails, check the values you entered and try again.
- When validation is successful, click Next.
-
In the Connection Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter
AMQ Broker 1
. -
In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter
Sample AMQ connection that uses the provided broker.
- In the upper right, click Create to see that the connection you created is now available. If you entered the example name, you would see that AMQ Broker 1 is now available.
5.2. Make a custom step available Link kopierenLink in die Zwischenablage kopiert!
Ignite provides a number of steps that operate on integration data between connections. If Ignite does not provide a between-connections step that meets your need, a developer can code an extension that defines one or more custom steps that operate on data between connections. The developer gives you a .jar
file that contains the extension. You then upload the extension in Ignite to make the custom step(s) available for use in integrations.
The AMQ to REST API sample integration uses a custom step that operates on data between connections to identify items that were damaged when they were received.
To make the Damage Reporter custom step available:
- In a new browser tab, go to https://github.com/syndesisio/fuse-online-sample-extension/releases.
-
Download the extension’s
.jar
file. - In Ignite, in the left panel, click Customizations.
- At the top, click Extensions.
- Click Import Extension.
-
Click Browse and select the downloaded
.jar
file that contains the extension. Ignite validates the file, extracts and displays the extension’s name, ID, and description, and lists Damage Reporter as the custom step that the extension defines. - Click Import. Ignite makes the custom step available and displays the extension details page.
For more information about coding an extension and creating its .jar
file, see the Tooling User Guide.
5.3. Create a REST API connector Link kopierenLink in die Zwischenablage kopiert!
Ignite can create connectors for REST APIs that support Hypertext Transfer Protocol (HTTP)/1.0 or HTTP/1.1. To do this, Ignite requires a valid Swagger 2.0 specification that describes a REST API you want to connect to.
Your Ignite installation provides the To Do app, which has a REST API for which a Swagger specification is available.
To create a REST API connector for the To Do app:
Identify the URL for your Ignite installation’s copy of the Swagger specification:
- In the Ignite navigation panel, click Home.
- Copy the URL into a text editor.
-
At the beginning of the URL, insert
todo-
. -
At the end of the URL, replace
dashboard
withswagger.json
.
The result is something like this:
https://todo-app-proj217402.6a63.fuse-ignite.openshiftapps.com/swagger.json
- In the Ignite navigation panel, click Customizations.
- Click Create API Connector.
- Select Use a URL.
- In the input box, paste the URL for your Swagger specification and click Next.
- On the Review Swagger Actions page, click Next. If you see a warning, you can ignore it.
- Click Next again to accept HTTP Basic Authorization.
On the Review/Edit Connector Details page, Ignite populates the fields with values from the Swagger specification.
- If you want to, you can change the values in the Connector Name and Description fields.
-
Confirm that the value in the Host field is correct. For example, it should be something like this:
https://todo-app-proj217402.6a63.fuse-ignite.openshiftapps.com
. -
Confirm that the value in the Base URL field is
/api
.
- Click Create Connector.
Ignite displays the API Client Connectors tab with an entry for the Todo App API that you just created.
5.4. Upload the To Do app icon Link kopierenLink in die Zwischenablage kopiert!
To show the flow of an integration, Ignite displays icons that identify the applications that the integration is connecting to. Your Ignite installation provides an icon for the REST API connector that you just created for the To Do app.
To upload the To Do app icon:
Display the To Do app icon:
- In a new browser tab, paste the URL for your Swagger specification.
-
At the end of the URL, replace
swagger.json
withimages/todo_icon.png
and click Enter. For example:https://todo-app-proj217402.6a63.fuse-ignite.openshiftapps.com/images/todo_icon.png
.
-
Save the
todo_icon.png
image. - In Ignite, in the API Client Connectors tab, click the entry for the Todo App API to display its details.
- On the Connector Details page, click Browse.
-
Navigate to
todo_icon.png
, select it, and click Open. - Refresh the display of the Connector Details page. The image now appears on the left.
5.5. Create a REST API connection Link kopierenLink in die Zwischenablage kopiert!
To create a connection to the To Do app REST API:
- In Ignite, in the left panel, click Connections to display any available connections.
- In the upper right, click Create Connection to display available connectors.
- Click the Todo App API connector that you just created.
- In the Todo App API Configuration, notice that Ignite populates the Authentication Type, Base Path, and Host fields from the connector information.
- In the Password field, enter any value. For this sample integration, password and user name values are required but they are not used.
- In the Username field, enter any value.
- Click Next.
-
In the Connection Name field, enter your choice of a name that helps you distinguish this connection from any other connections. For example, enter
Todo App API Client
. -
In the Description field, optionally enter any information that is helpful to know about this connection. For example, enter
Connection to the provided Todo app REST API.
- In the upper right, click Create to see that the connection you created is now available.
5.6. Create and deploy AMQ to REST API sample integration Link kopierenLink in die Zwischenablage kopiert!
To create and deploy the AMQ to REST API sample integration, the main steps are:
5.6.1. Choose the start connection Link kopierenLink in die Zwischenablage kopiert!
To choose the start connection:
- On the left, click Integrations.
- Click Create Integration.
- On the Choose a Start Connection page, click your AMQ connection. If you specified the example name, you would click AMQ Broker 1.
- On the Choose an Action page, click the Subscribe for Messages action to receive messages from the queue you specify.
-
In the Destination Name field, enter
inventoryReceived
for the name of the queue to obtain data from. - Click in the Destination Type field and select Queue.
- Leave the other fields blank.
- Click Done to add the start connection to the integration.
After connecting to AMQ, the integration watches for messages on the inventoryReceived
queue. When a message is available, the integration passes it to the Damage Reporter step. However, before you can add that step to the integration, you must choose the integration’s finish connection.
5.6.2. Choose the finish connection Link kopierenLink in die Zwischenablage kopiert!
To add the finish connection to the integration:
- On the Choose a Finish Connection page, click the To Do app connection that you created. If you assigned the example name, you would click Todo App API Client.
- On the Choose an Action page, click Create new task, which provides information about who to contact to address a particular damaged item.
5.6.3. Add a damage reporter step Link kopierenLink in die Zwischenablage kopiert!
With the start and finish connections in place, you are ready to add the custom step that receives the messages from the AMQ broker and identifies any items that were damaged when they were received.
To add the custom damage reporter step:
- In the center, click Add a Step.
- On the Choose a Step page, click Damage Reporter.
5.6.4. Add a data mapping step Link kopierenLink in die Zwischenablage kopiert!
Add a data mapping step that correlates the task
field in the output from the damage reporter step to the task
field in the database that the REST API accesses:
- In the left panel, hover over the plus sign between the damage reporter step and the finish connection to display a pop-up in which you click Add a Step.
- On the Choose a Step page, click Data Mapper. In the data mapper, the Sources panel on the left displays the fields in the output from the damage reporter step. The Target panel on the right displays the fields in the database that the API accesses.
-
In the Sources panel, click the
task
field. -
In the Target panel, expand the
body
field and clicktask
. - Click Done.
5.6.5. Give the integration a name and deploy it Link kopierenLink in die Zwischenablage kopiert!
The sample integration is complete. To deploy it:
- In the upper right, click Publish to give it a name.
-
In the Integration Name field, enter a name for the integration. For example,
AMQ to REST API Sample Integration
. - Optionally, in the Description field, enter information that might be helpful to know about this integration.
- In the upper right corner, click Publish.
Ignite displays the integration summary page with a Publishing spinning circle. Ignite is generating the runtime for the integration and will start it when the runtime is ready. This takes a few minutes.
A Fuse Online account is limited to a specific number of integrations that can be running at one time. For details, see the pricing plan. If you are already running the maximum number of integrations, then you must unpublish an integration before you can publish (start running) another one.
If you are using a Fuse Online evaluation account, then only one integration at a time can be running (published). If you already created one of the other sample integrations and that integration is running then this integration is automatically in the Unpublished state. You must stop the running integration by unpublishing it. You can then publish this integration.
If you are already running the maximum number of integrations, follow these steps to unpublish (stop) an integration:
- In the left panel, click Integrations.
-
In the entry for the integration that you want to stop, click
on the far right.
- In the popup, click Unpublish.
After unpublishing an integration, start another integration as follows:
- In the left panel, click Integrations.
-
In the entry for the integration that you want to start, click
on the far right.
- In the popup, click Publish.
5.7. Confirm that the AMQ to REST API integration works Link kopierenLink in die Zwischenablage kopiert!
To confirm that the AMQ to REST API integration is working:
- In the left panel, click Integrations.
- Confirm that your AMQ to REST API integration is Published, which means that it is running. The integration must be Published before you continue with these instructions.
-
In a new browser window, go to the To Do app display by inserting
todo-
in front of the URL for your Ignite installation. For example:https://todo-app-proj7614.6a63.fuse-ignite.openshiftapps.com/
. - In the To Do app display, click Show JMS Form to display an input box that contains an XML message.
Click Send JMS Message to send that message to the AMQ broker in your OpenShift project.
Successful execution returns a task from the To Do app client API. The task identifies the ID of the damaged item and the contact information for its vendor.
Edit the XML message to specify two damaged items:
- Click Show JMS Form to display the message input box again.
-
In the XML message, change the entry for the undamaged item to specify
damaged="true"
. - Click Send JMS Message. The To Do app client API returns a new task that contains IDs for two damaged items and contact information for the two vendors.
Edit the XML message to specify an unknown vendor:
- Click Show JMS Form.
-
In the XML message, for an item that has
damaged="true"
, change the name of the vendor. - Click Send JMS Message. The To Do app client API returns a new task that indicates that there is no contact information for the vendor of a damaged item. The To Do app accesses a database that has only two vendors.
5.8. Clean up your integration Link kopierenLink in die Zwischenablage kopiert!
When you are done working with a sample integration, unpublish it and delete it:
- In the left panel, click Integrations.
- In the main panel, identify the entry for the sample integration that you want to unpublish.
-
In that entry, to the right, click
and then click Unpublish.
- Click OK to confirm that you want to stop running the integration.
-
In the entry for the integration that you just unpublished, to the right, click
and then click Delete.
- Click OK to confirm that you want to delete the integration.