Reading Time: 9 minutes

After the Anypoint Code Builder October 2024 Release, the AsyncAPI/EDA support now includes the capability to design, govern, and implement AsyncAPI specifications across four event brokers: 

  • Anypoint MQ
  • Kafka
  • Solace
  • Salesforce Platform Events

With these additions, you don’t have to leave Anypoint Code Builder (ACB) to build your AsyncAPIs from the design to the implementation. But what exactly does this process look like in an actual example? Let’s see a preview.

Design an AsyncAPI specification in ACB

We previously learned how to design AsyncAPI specifications with a practical example where we created the architecture to implement two services: an Accounts Service and an Email Service. The Accounts Service publishes a message to the Message Broker whenever a new user signs up to a website. At the same time, the Email Service is responsible for sending an email to the user who just signed up, meaning the Email Service is subscribed to the Message Broker.

To make things easier, instead of designing and implementing both services in this post, let’s just focus on the Email Service. Let’s start by designing this AsyncAPI specification.

In Anypoint Code Builder, select Design an API. Add the Project Name Email Service and make sure to select AsyncAPI and version 2.6 with YAML.

design an API

Once the project opens in the YAML file, paste this code into this file. Note that this specification uses Anypoint MQ as the Message Broker, but as mentioned before, you can use any of the four brokers listed at the beginning of this post. You can learn more about the different brokers here.

After that, you can open the API Console using the button at the top right of the screen, located next to the API Governance button. This will open a preview similar to what you normally see in Exchange.

API console

After verifying this information, let’s make sure we’re following best practices using the API Governance tool in ACB.

Add API Governance

Click on the Show API Governance button at the top-right side of the screen. This will open the Governance Rulesets menu on the Explorer at the left. Click on Add Rulesets. Search for the AsyncAPI Best Practices ruleset and add it to the project. Make sure you’re logged in to Anypoint Platform or log in when you see the prompt.

Once the ruleset is added, run it by using the “play” button next to the ruleset in the Explorer. You will now see which rules are passing and which have a warning. We don’t have any errors in the results. 

Use this specification to fix all the warnings and re-run the ruleset to make sure everything is green now.

Once you verify this, you are ready to publish your specification to Exchange.

Publish to Anypoint Exchange

Open the Command Palette by using cmd+shift+P in Mac or ctrl+shift+P in Windows. Search for and select the MuleSoft: Publish API Specification to Exchange option.

Leave all the defaults and keep pressing Enter when ACB asks for your business group, project name, artifact ID, asset version, and API version. Wait until the API Specification is published and you see the following prompt.

This means it’s now time to start implementing your Mule application.

Implement the Mule Application

Select Yes on the previous prompt and write email-service as the project name. Select a folder, the Mule Runtime version 4.8.0, and the Java version 17. Once the project finishes processing, you will see a screen similar to the following.

As you can see, the Mule application was created with all the basic configurations and components for you to continue implementing. You do not have to start building from scratch thanks to everything you defined in your specification.

After you implement all the code needed for your use case, you are ready to start testing locally or deploy to CloudHub and test from there. If you want to take a look at the full implementation of this API using Anypoint MQ as the Message Broker, learn how to develop AsyncAPIs with Anypoint MQ and Anypoint Code Builder.

ACB just keeps getting better

Anypoint Code Builder keeps improving with each new release, and it won’t be long before we can completely replace Anypoint Studio with this Visual Studio Code-based IDE.

Plus, we can start seeing different use cases that can be completely done with ACB. For example, REST APIs, API-led, and now AsyncAPIs. The only other major update we’re missing on ACB is the possibility of creating MUnits as we do in Studio. But don’t worry, it’ll come!

In the meantime, don’t miss the following resources:

Read

Watch

Try