検索

このコンテンツは選択した言語では利用できません。

Chapter 5. Implement an AMQ to REST API sample integration

download PDF

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 Fuse Online. This integration also does that, but in addition, it provides instructions for customizing and extending Fuse Online 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 an OpenAPI (Swagger) file.

Fuse Online provides the extension file and the OpenAPI file.

To create this integration, you must be logged in to Fuse Online. If you are not already logged in, see Chapter 2, What to expect when using Fuse Online for the first time.

To implement the AMQ to REST API sample integration, the main steps are:

5.1. Create an AMQ connection

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

To start the AMQ broker:

  1. In a browser, go to the OpenShift Web Console. Your Fuse Online environment runs on OpenShift Online.
  2. In the console, on the right, under My Projects, click Fuse Online to display the project’s overview.

    Your project’s name is something like proj123456.

  3. In the overview, click the first entry, broker-amq, #1 to expand the entry for the provided AMQ broker.
  4. On 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

To complete this procedure, you must be logged in to your Fuse Online environment. If you are not already logged in, see Chapter 2, What to expect when using Fuse Online for the first time.

To create a connection to the AMQ broker that is running in your Fuse Online project in OpenShift:

  1. In Fuse Online, in the left panel, click Connections to display any available connections.
  2. In the upper right, click Create Connection to display Fuse Online connectors.
  3. Click the AMQ connector.
  4. Configure the connection by entering:

    1. In the Broker URL field, enter tcp://broker-amq-tcp:61616 as the location to obtain data from.
    2. In the Username field, enter amq as the user name for the account that accesses this AMQ broker.
    3. In the Password field, enter topSecret as the password for the account that accesses this AMQ broker.
    4. Leave the other fields blank.
  5. Click Validate. Fuse Online 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.
  6. When validation is successful, click Next.
  7. 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.
  8. 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.
  9. 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

Fuse Online provides a number of steps that operate on integration data between connections. If Fuse Online 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 Fuse Online 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:

  1. In a new browser tab, go to https://github.com/syndesisio/fuse-online-sample-extension/releases.
  2. Download the extension’s .jar file.
  3. In Fuse Online, in the left panel, click Customizations.
  4. At the top, click Extensions.
  5. Click Import Extension.
  6. Click Browse and select the downloaded .jar file that contains the extension. Fuse Online 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.
  7. Click Import. Fuse Online makes the custom step available and displays the extension details page.
Note

For more information about coding an extension and creating its .jar file, see the Tooling User Guide.

5.3. Create a REST API connector

Fuse Online can create connectors for REST APIs that support Hypertext Transfer Protocol (HTTP)/1.0 or HTTP/1.1. To do this, Fuse Online requires a valid OpenAPI 2.0 specification that describes a REST API you want to connect to.

Your Fuse Online installation provides the To Do app, which has a REST API for accessing a database that contains tasks. Your installation also provides an OpenAPI (Swagger) specification for this API.

To create a REST API connector for the To Do app:

  1. Identify the URL for your Fuse Online installation’s copy of the OpenAPI specification:

    1. In the Fuse Online navigation panel, click Home.
    2. Copy the URL into a text editor.
    3. At the beginning of the URL, insert todo-.
    4. At the end of the URL, replace dashboard with swagger.json.

    The result is something like this: https://todo-app-proj217402.6a63.fuse-ignite.openshiftapps.com/swagger.json

  2. In the Fuse Online navigation panel, click Customizations.
  3. Click Create API Connector.
  4. Select Use a URL.
  5. In the input box, paste the URL for your OpenAPI specification and click Next.
  6. On the Review OpenAPI Actions page, click Next. If you see a warning, you can ignore it.
  7. Click Next again to accept HTTP Basic Authorization.
  8. On the Review/Edit Connector Details page, Fuse Online populates the fields with values from the OpenAPI specification.

    1. If you want to, you can change the values in the Connector Name and Description fields.
    2. 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.
    3. Confirm that the value in the Base URL field is /api.
  9. Click Create API Connector.

Fuse Online 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

To show the flow of an integration, Fuse Online displays icons that identify the applications that the integration is connecting to. Your Fuse Online installation provides an icon for the To Do app.

To upload the To Do app icon:

  1. Display the To Do app icon:

    1. In a new browser tab, paste the URL for your OpenAPI (Swagger) specification.
    2. At the end of the URL, replace swagger.json with images/todo_icon.png and click Enter. For example: https://todo-app-proj217402.6a63.fuse-ignite.openshiftapps.com/images/todo_icon.png.
  2. Save the todo_icon.png image.
  3. In Fuse Online, in the API Client Connectors tab, click the entry for the Todo App API to display its details.
  4. On the Connector Details page, click Browse.
  5. Navigate to todo_icon.png, select it, and click Open.
  6. Refresh the display of the Connector Details page. The image now appears on the left.

5.5. Create a REST API connection

To create a connection to the To Do app REST API:

  1. In Fuse Online, in the left panel, click Connections to display any available connections.
  2. In the upper right, click Create Connection to display available connectors.
  3. Click the Todo App API connector that you just created.
  4. In the Todo App API Configuration, notice that Fuse Online populates the Authentication Type, Base Path, and Host fields from the connector information.
  5. In the Username field, enter any value. For this sample integration, user name and password values are required but they are not used.
  6. In the Password field, enter any value.
  7. Click Next.
  8. 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.
  9. 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.
  10. 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

To create and deploy the AMQ to REST API sample integration, the main steps are:

5.6.1. Choose the start connection

To choose the start connection:

  1. In Fuse Online, on the left, click Integrations.
  2. Click Create Integration.
  3. On the Choose a Start Connection page, click your AMQ connection. If you specified the example name, you would click AMQ Broker 1.
  4. On the Choose an Action page, click the Subscribe for Messages action to receive messages from the queue you specify.
  5. In the Destination Name field, enter inventoryReceived for the name of the queue to obtain data from.
  6. Click in the Destination Type field and select Queue.
  7. Leave the other fields blank.
  8. Click Next. Fuse Online prompts you to specify the output data type. This is not needed for this sample integration.
  9. 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

To add the finish connection to the integration:

  1. In Fuse Online, 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.
  2. 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

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:

  1. In Fuse Online, in the center, click Add a Step.
  2. On the Choose a Step page, click Damage Reporter.

5.6.4. Add a data mapping step

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:

  1. In Fuse Online, 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.
  2. 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.
  3. In the Sources panel, click the task field.
  4. In the Target panel, expand the body field and click task.
  5. Click Done.

5.6.5. Give the integration a name and deploy it

The sample integration is complete. To deploy it:

  1. In Fuse Online, in the upper right, click Publish to give it a name.
  2. In the Integration Name field, enter a name for the integration. For example, AMQ to REST API Sample Integration.
  3. Optionally, in the Description field, enter information that might be helpful to know about this integration.
  4. In the upper right corner, click Publish.

Fuse Online displays the integration summary page with a progress indicator that shows the publishing stages. Fuse Online is generating the runtime for the integration and will start it when the runtime is ready. This takes a few minutes.

Note

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 stop an integration before you can start running another one.

If you are using a Fuse Online evaluation account, then only one integration at a time can be running. If you already created one of the other sample integrations and that integration is running then this integration is automatically in the Stopped state. You must stop the running integration and then you can then publish this integration.

If you are already running the maximum number of integrations, follow these steps to stop an integration:

  1. In the left panel, click Integrations.
  2. In the entry for the integration that you want to stop, click ThreeVerticalDotsKebab on the far right.
  3. In the popup, click Stop.

After stopping an integration, start another integration as follows:

  1. In the left panel, click Integrations.
  2. In the entry for the integration that you want to start, click ThreeVerticalDotsKebab on the far right.
  3. In the popup, click Publish.

5.7. Confirm that the AMQ to REST API integration works

To confirm that the AMQ to REST API integration is working:

  1. In Fuse Online, in the left panel, click Integrations.
  2. Confirm that your AMQ to REST API integration is Running. The integration must be Running before you continue with these instructions.
  3. In a new browser window, go to the To Do app display by inserting todo- in front of the URL for your Fuse Online installation. For example: https://todo-app-proj7614.6a63.fuse-ignite.openshiftapps.com/.
  4. In the To Do app display, click Show JMS Form to display an input box that contains an XML message.
  5. 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. If the task does not appear in a moment or two, try reloading the page.

  6. Edit the XML message to specify two damaged items:

    1. Click Show JMS Form to display the message input box again.
    2. In the XML message, change the entry for the undamaged item to specify damaged="true".
    3. 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.
  7. Edit the XML message to specify an ID that you make up:

    1. Click Show JMS Form.
    2. In the XML message, for the item that has damaged="true", change the item ID, for example, to 1234.
    3. Click Send JMS Message. The To Do app client API returns a new task with the item ID that you just entered.

5.8. Clean up your integration

When you are done working with a sample integration, stop it and delete it:

  1. In Fuse Online, in the left panel, click Integrations.
  2. In the main panel, identify the entry for the sample integration that you want to stop.
  3. In that entry, to the right, click Kebab Menu and then click Stop.
  4. Click Stop to confirm that you want to stop running the integration.
  5. In the entry for the integration that you just stopped, to the right, click Kebab Menu and then click Delete.
  6. Click Delete to confirm that you want to delete the integration.
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.