-
Notifications
You must be signed in to change notification settings - Fork 78
Add enterprise intergration patterns content #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pasindufernando1
wants to merge
8
commits into
wso2:5.1.x
Choose a base branch
from
pasindufernando1:EIP
base: 5.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
167179b
Add initial structure
pasindufernando1 8f7176e
Add type diagrams
pasindufernando1 bc7b46c
Improve/proof read the content
pasindufernando1 2e1cc00
Remove em dashes
pasindufernando1 9494633
Address PR suggestions
pasindufernando1 193c396
Remove external reference
pasindufernando1 c8375cd
Use base url for images
pasindufernando1 7cdeb17
Merge remote-tracking branch 'upstream/main' into EIP
pasindufernando1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| title: Aggregator | ||
| description: "Implement the Aggregator pattern with WSO2 Integrator." | ||
| --- | ||
|
|
||
| import TabItem from '@theme/TabItem'; | ||
| import { | ||
| EipReferenceLink, | ||
| PatternImage, | ||
| PatternImplementationTabs, | ||
| } from '@site/src/utils/eipPatternComponents'; | ||
|
|
||
| # Aggregator | ||
|
|
||
| Use an Aggregator to collect individual but related messages and publish a single combined message once the set is complete. <EipReferenceLink href="https://www.enterpriseintegrationpatterns.com/patterns/messaging/Aggregator.html" label="Enterprise Integration Patterns Aggregator reference" /> | ||
|
|
||
| In WSO2 Integrator, the aggregator keeps the partial messages in a map keyed by a correlation identifier, appends each arriving message to its group, and sends the combined message when the completeness condition is met. | ||
|
|
||
| ## Example: Combining multi-part survey responses | ||
|
|
||
| This example collects survey form submissions that arrive one section at a time. Each submission is correlated by the `userId` header and stored with the user's earlier sections. When all three sections have arrived, the aggregator submits the complete survey to the survey API and clears the stored parts. | ||
|
|
||
| <PatternImplementationTabs> | ||
| <TabItem value="ui" label="Visual Designer" default> | ||
|
|
||
| 1. Create an [HTTP service](../../develop/integration-artifacts/service/http.md#creating-an-http-service) with a `post` resource that accepts the survey section payload and the `userId` correlation header. | ||
| 2. Add an HTTP client connection for the survey submission API. See [adding a connection](../../develop/integration-artifacts/supporting/connections.md#adding-a-connection). | ||
| 3. In the flow, look up the user's partial submissions in the aggregation map by `userId`. | ||
| 4. Add an [If node](../../develop/understand-ide/editors/flow-diagram-editor/control.md#if): when no entry exists, store the first section; otherwise append the new section. | ||
| 5. When the stored sections reach the completeness condition (three sections), post the combined survey to the submission endpoint and remove the entry from the map. | ||
|
|
||
| In the flow, the **If** node checks whether this is the user's first survey section; once three sections have accumulated, the combined survey is posted and the stored parts are cleared: | ||
|
|
||
| <PatternImage src="/img/eip-patterns/aggregator_flow.png" alt="Aggregator flow in the WSO2 Integrator visual designer" width={760} /> | ||
|
|
||
| </TabItem> | ||
| <TabItem value="code" label="Ballerina Code"> | ||
|
|
||
| ```ballerina | ||
| // docs-fold-start: Supporting definitions | ||
| import ballerina/http; | ||
|
|
||
| final http:Client formSubmitClient = check new ("http://api.surveyme.com.balmock.io"); | ||
| // docs-fold-end | ||
|
|
||
| map<json[]> partialSurveys = {}; | ||
|
|
||
| listener http:Listener httpListener = new (port = 8080); | ||
|
|
||
| service /api/v1 on httpListener { | ||
| resource function post survey/[string id](@http:Header string userId, @http:Payload json formData) returns error? { | ||
| json[]|() surveyData = partialSurveys[userId]; | ||
| if surveyData == () { | ||
| json[] newSurvey = [formData]; | ||
| partialSurveys[userId] = newSurvey; | ||
| } else { | ||
| () var1 = surveyData.push(formData); | ||
| if surveyData.length() == 3 { | ||
| http:Response response = check formSubmitClient->/survey/[id]/submit.post({userId: surveyData}, targetType = http:Response); | ||
| json[] remove = partialSurveys.remove(userId); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </PatternImplementationTabs> | ||
|
|
||
| ## Complete sample | ||
|
|
||
| The complete project is available in the [aggregator sample](https://github.com/wso2/integration-samples/tree/main/integrator-default-profile/enterprise-integration-pattern/aggregator) on GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| --- | ||
| title: Command Message | ||
| description: "Implement the Command Message pattern with WSO2 Integrator." | ||
| --- | ||
|
|
||
| import TabItem from '@theme/TabItem'; | ||
| import { | ||
| EipReferenceLink, | ||
| PatternImage, | ||
| PatternImplementationTabs, | ||
| } from '@site/src/utils/eipPatternComponents'; | ||
|
|
||
| # Command Message | ||
|
|
||
| Use a Command Message to invoke a procedure in another application through messaging. The message carries the command and its parameters, and the receiver executes it. <EipReferenceLink href="https://www.enterpriseintegrationpatterns.com/patterns/messaging/CommandMessage.html" label="Enterprise Integration Patterns Command Message reference" /> | ||
|
|
||
| In WSO2 Integrator, a command message is a typed record sent to the operation endpoint of the receiving application. The record fields are the procedure's parameters, and the response confirms the command's outcome. | ||
|
|
||
| ## Example: Creating a Slack user group | ||
|
|
||
| This example receives a user group creation request and sends it as a command message to the Slack `usergroups.create` API. The `UserGroupCreateRequest` record carries the command parameters, and Slack executes the procedure and returns the created group. | ||
|
|
||
| <PatternImplementationTabs> | ||
| <TabItem value="ui" label="Visual Designer" default> | ||
|
|
||
| 1. Create an [HTTP service](../../develop/integration-artifacts/service/http.md#creating-an-http-service) with a `post` resource that accepts the `UserGroupCreateRequest` payload. | ||
| 2. Add an HTTP client connection for the Slack API. See [adding a connection](../../develop/integration-artifacts/supporting/connections.md#adding-a-connection). | ||
| 3. In the flow, post the command message to the `usergroups.create` operation with the `x-www-form-urlencoded` media type. | ||
| 4. Return the `UserGroupCreationResponse` to the caller. | ||
|
|
||
| The `UserGroupCreateRequest` record is the command message, and its fields (`name`, `description`, and `team_id`) are the parameters of the procedure to invoke: | ||
|
|
||
| <PatternImage src="/img/eip-patterns/command_message_types.png" alt="UserGroupCreateRequest command message type in WSO2 Integrator" width={285} /> | ||
|
|
||
| The flow forwards the command message to Slack's `usergroups.create` operation and returns the result: | ||
|
|
||
| <PatternImage src="/img/eip-patterns/command_message_flow.png" alt="Command Message flow in the WSO2 Integrator visual designer" width={530} /> | ||
|
|
||
| </TabItem> | ||
| <TabItem value="code" label="Ballerina Code"> | ||
|
|
||
| ```ballerina | ||
| // docs-fold-start: Supporting definitions | ||
| import ballerina/http; | ||
|
|
||
| type UserGroupCreateRequest record {| | ||
| string name; | ||
| string description; | ||
| string team_id; | ||
| |}; | ||
|
|
||
| type UserGroup record { | ||
| string id; | ||
| boolean is_usergroup; | ||
| string 'handle; | ||
| boolean is_external; | ||
| int date_create; | ||
| string created_by; | ||
| string user_count; | ||
| string name; | ||
| string description; | ||
| string team_id; | ||
| }; | ||
|
|
||
| type UserGroupCreationResponse record { | ||
| boolean ok; | ||
| UserGroup usergroup?; | ||
| string 'error?; | ||
| }; | ||
|
|
||
| final http:Client slackClient = check new ("http://api.slack.com.balmock.io"); | ||
| // docs-fold-end | ||
|
|
||
| listener http:Listener httpListener = new (port = 8080); | ||
|
|
||
| service /api/v1 on httpListener { | ||
| isolated resource function post createUserGroup(UserGroupCreateRequest userGroup) | ||
| returns UserGroupCreationResponse|error { | ||
| UserGroupCreationResponse userGroupCreateRequest = check slackClient->/api/usergroups\.create.post(userGroup, mediaType = "x-www-form-urlencoded"); | ||
| return userGroupCreateRequest; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </PatternImplementationTabs> | ||
|
|
||
| ## Complete sample | ||
|
|
||
| The complete project is available in the [command message sample](https://github.com/wso2/integration-samples/tree/main/integrator-default-profile/enterprise-integration-pattern/command_message) on GitHub. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.