Content-based routing (CBR) is the way we determine which flow should be run when a single AS2 connection is used in multiple flows. When you create multiple flows with the same AS2 connection, integrator.io uses content-based routing to determine which flow to run for a given message.
See how files sent with AS2 are synced
To understand how CBR works, and at what point in the integration process it’s used, it’s helpful to understand how a message sent through an AS2 connection on integrator.io is routed to the flow that it’s intended for.
We handle messages sent through an AS2 connection in stages that follow this order:
- Receive a message: There is only one URL integrator.io uses to receive messages: https://api.integrator.io/v1/as2.
- Check the receiver: We look at the unique ID of the recipient. The ID tells us which integrator.io account is meant to receive this message.
- Example: Your partner, Walmart, sends you a file of sales orders. When Walmart sends the file, your unique ID is in one of the headers.
- Check the sender: We look at the unique ID of the sender. The combination of the sender and recipient IDs tells us which connection the info belongs to.
- Example: When your partner, Walmart, sends a file of sales orders to you through an AS2 connection, their ID will be in the AS2 message header.
- Look at the content (CBR): In the case of a single AS2 connection used in multiple flows, we need to figure out which flow a given message is meant to run. We use the routing rules you define with a small amount of JavaScript to identify the right flow. You will use components from a message from your trading partner, like the form type or a header name, in the code you write. The function output must result in the ID number of the flow you want to route the message to. The message will then run the intended flow. We call this content-based routing.
- Example: You have a flow set up to sync your Walmart sales orders with your NetSuite ERP, and a separate flow that syncs your Walmart change orders with your Shopify shipping orders. We have to look at the content of the message being sent to you from Walmart to know which flow the files should be run through.
- Choose the flow: After we’ve identified who the message is to, who it’s from, and what kind of data files are being sent, we send the files to the intended flow.
How CBR rules work
In step 4 above, “Look at the content (CBR),” we see at what point in the reception of a message through an AS2 connection CBR would be used. We also see that the routing process is determined by rules that have been pre-set by you, the user. The way you will set these rules is by writing a small amount of JavaScript in our Routing Rules Editor. You will write the scipt with components from a message from your trading partner. The output must be the ID of the flow you want the message to run. You can find the flow ID in the URL of the flow.
You will know if and when you need to set rules because integrator.io will prompt you once it recognizes that one AS2 connection is being used in more than one flow. [i]
Understand the Routing Rules Editor
You will use the Routing Rules Editor to define the rules that integrator.io will use to send messages from your trading partners to the right flow.
- Function name: You can change the function name to meet your integration’s needs.
- Script: You can use a script you’ve already written and saved. If you know you will want to reuse the script that you’ve just written, you can save it by clicking the plus sign next to the Script dropdown. A window will pop up on your screen prompting you to name the script and add a description.
- Insert contentBasedFlowRouter stub: The stub is the combination of the comment and the sample function in the “Script content” panel. It explains the structure of the ‘options’ argument that will be passed to the function, that you can change the name of the function, and what the output needs to be. Beneath the comment, in multi-colored text, is a sample function. You can delete the stub to write your script. If you need info from the stub, you can reinsert it with this button.
- Script content panel: You will write your code in this panel. You will also find the comment that explains the structure of the argument that will be passed to the function you are writing and what the function output needs to be. Below the comment, you will find a sample function.
- Function input panel: In this panel, you will find a sample of the type of message you will receive from your trading partner. It will be displayed in the ‘options’ argument structure described in the contentBasedFlowRouter stub. You can modify the content of this panel.
- Example: You can paste an EDI message from your trading partner into this panel. Then, you can use the info from this panel in the functions you write to define your routing criteria. You will write the functions in the “Script content” panel.
- Function output panel: When you have written your script, you can test it by clicking the Preview button at the bottom right of the editor. Your results will appear in this panel.
- Preview: To see the output of your function before you accept it, you will need to click this button. The output will appear in the “Function output panel” at the bottom right of the editor.
- Cancel: You can cancel any changes you’ve made at any point without saving them.
- Accept: When you’ve written the rule that you need, and you’re ready to move on, click Accept.
Set the rules
When you use an existing AS2 connection to build a flow, a message will pop up on your screen.
Note: You’ll need to get the ID for the flow you’re setting you’re setting up rules for from that flow’s URL before your start.
- At the bottom right of the pop up, click Routing Rules Editor. The editor will open on your screen. You can change the rules at any time. Use the Export Form to launch the Routing Rules Editor. The Routing Rules Editor button will be in the middle of the form.

- On the right, you can paste sample data from a message from your trading partner into the “Function input” panel. Identify the message components you want to build your functions with.
- On the left, write your functions or insert functions from scripts you already have saved in integrator.io.
- At the bottom right, click Preview. In the bottom left under “Function output,” make sure that the output is the ID number of the flow you want the message to run
- When you’re ready to save your code, at the bottom right, click Accept.
Find out more on AS2 connections and how to set one up.
Comments
0 comments
Please sign in to leave a comment.