Trying it without a partner
This page shows how to exchange AS2 messages with yourself, on one machine. You run a second MicroB2B that plays your partner, Acme. It is a safe way to learn the setup before you connect a real partner.
Follow the quick start first. This page assumes the first instance runs on port 8080 from ~/microb2b-demo, and that you made us.crt, us.key, acme.crt and acme.key there.
How the two instances fit together
| First instance | Second instance | |
|---|---|---|
| Plays | You (MICROB2B) | Your partner (ACME) |
| Web UI | http://localhost:8080/ | http://127.0.0.1:8090/ |
| AS2 receiver | Port 8081 | Port 8082 |
| Directory | ~/microb2b-demo | ~/microb2b-demo-acme |
Each instance has its own directory, database, keys and user.
1. Start the second instance
The second instance needs its own web port, address and keys. Make them in a new directory:
mkdir -p ~/microb2b-demo-acme && cd ~/microb2b-demo-acme
cat > microb2b.env <<KEYS
export HTTP_PORT=8090 PUBLIC_URL=http://127.0.0.1:8090
export SESSION_KEY=$(openssl rand -base64 32)
export SECRETS_KEY=$(openssl rand -base64 32)
KEYS
chmod 600 microb2b.env
. ./microb2b.env
microb2b users create admin
microb2b standaloneOpen the setup link it printed and set up the user, as for the first instance.
The log shows AS2 receiver HTTP server error ... address already in use. That is expected. The second instance’s AS2 receiver also wants port 8081, which the first instance holds. Everything else runs, and you fix the port in step 4.
2. Use a different host name for each instance
Open the second instance as http://127.0.0.1:8090/ and the first as http://localhost:8080/.
Why: browsers keep cookies per host name, not per port. Two instances under the same host name overwrite each other’s sign-in. You are then signed out, or forms fail with CSRF token invalid.
3. Mirror the setup
Configure the second instance as in the quick start, with the roles swapped:
| First instance (8080) | Second instance (8090) | |
|---|---|---|
| Our certificate (with key) | us.crt + us.key | acme.crt + acme.key |
| Partner certificate | acme.crt | us.crt |
| Organization | local, AS2 ID MICROB2B | Rename local to acme on its edit page, AS2 ID ACME |
| Partner | acme, AS2 ID ACME | local, AS2 ID MICROB2B |
| Partner endpoint | http://localhost:8082/as2 | http://localhost:8081/as2 |
The certificate files are in ~/microb2b-demo. Upload them from there on both instances.
Why rename? The organization’s name is how routes and folders name it. Renaming local to acme makes the second instance’s files and messages say acme. It also frees the name local for the partner.
4. Move the second receiver to port 8082
On the second instance:
- Go to Plugins > AS2 Receivers and open
as2_receiver_default. - Set Port to
8082and save. - Go to System > Services and restart
as2_receiver_default.
A plugin instance reads its settings when it starts. That is why the restart is needed. The receiver should now show as running.
5. Send in both directions
From the first instance to the second:
mkdir -p ~/microb2b-demo/data/outbox/acme
echo "Hello Acme" > ~/microb2b-demo/data/outbox/acme/hello.txtThe file arrives in ~/microb2b-demo-acme/data/inbox/local/hello.txt.
From the second instance to the first:
mkdir -p ~/microb2b-demo-acme/data/outbox/local
echo "Hello back" > ~/microb2b-demo-acme/data/outbox/local/reply.txtThe file arrives in ~/microb2b-demo/data/inbox/acme/reply.txt.
On both instances, Messaging > Messages shows each message as Delivered. The sending side shows the partner’s receipt on the message’s page.
If it does not work
- The message is Retrying with
connection refused. The other instance’s receiver is not running on the port in the endpoint. Check System > Services on that instance. - The message is Error, and its history names
decryption-failedorauthentication-failed. A certificate is swapped. Check the table in step 3. - The message is Error, and its history says no AS2 profile was found. The organization or the partner on that instance has no AS2 profile yet.
- The file moves to
data/outbox/unroutable/. The folder name must be the partner’s name on that instance:acmeon the first,localon the second. A.reason.txtfile beside it says why.
See Troubleshooting for more.
When you are done
Stop each instance with Ctrl-C. It finishes the work in hand and stops cleanly. To start again, run . ./microb2b.env and microb2b standalone in the instance’s directory.