How to publish Mule 4 Custom Connector to Anypoint Exchange
Anypoint Exchange allows us to share and discover the assets like API Specifications, Connectors etc on Anypoint Platform. API Specification assets can directly be created on Anypoint Exchange, while the Custom Connectors needs to be published as a part of release process. Anypoint platform provides a Maven plugin to publish these custom connectors to Exchange.
I recently created a custom Mule 4 connector that allows us connect to Google Firebase Realtime database. In this post, we will see how we can share this new connector with other developers in our organization using Anypoint Exchange.
1. Deploy Connector
Step 1: Get Access Keys
Login to Anypoint Platform and get your Organization Id -
Step 2: Change Group Id
To publish to Anypoint Exchange, we will need use Organization Id as a Maven Group Id for your connector -
<groupId>{ORGANIZATION_ID}</groupId>
If you are publishing a MuleSoft Certified Connector, you maybe able to use org.mule.modules as a groupId.
|
Step 3: Maven Distribution Management
Add Exchange specific repositories under distributionManagement
section of pom -
<distributionManagement>
<snapshotRepository>
<id>exchange-repository</id>
<name>Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{Your ORG ID}/maven</url>
<layout>default</layout>
</snapshotRepository>
<repository>
<id>exchange-repository</id>
<name>Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{Your ORG ID}/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>
If you are also publishing connectors to your local Maven repository (eg. Artifactory), you may need more repositories under distribution management section. Maven only allows one repository and snapshotRepository in a distribution management section. If you need multiple, you may create profiles and configure the distribution management for each profile. Then you can activate the profile using -P
switch.
Step 4: Configure Exchange Credentials
We need to configure Anypoint Exchange credentials to access the Exchnage repository for deployment.
For this, we need to add a server
entry in ~/.m2/settings.xml
file. The id
of this element must match with the id
used in distributionManagement
section.
There are two ways to add credentials -
-
We can use Anypoint Platform username and password (maybe, create a user for this specific purpose).
-
Get the Access Token for the user and use that as username with
ACCESS_TOKEN
as a password. While you are logged into the Anypoint Platform, access https://anypoint.mulesoft.com/accounts/api/profile and search for 'access-token' in the response.
<servers>
<server>
<id>exchange-repository</id>
<username>XXXXXX-XXXX-XXX-XXX-XXXXXXX</username>
<password>ACCESS_TOKEN</password>
</server>
</servers>
Step 5: Deploy
At this point, we are now ready to deploy the connector to Anypoint Exchange. Run mvn deploy
command and watch out for the Success!
Now, we can see the connector published under our Organization on Anypoint Exchange -
2. Share Connector
Select the connector to see the dependency information for new connector. You can also add connector documentation such as how to install or use.
You must add an exchange repository in your project pom to use connector from exchange -
<repositories>
<repository>
<id>Repository</id>
<name>Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/{Your ORG ID}/maven</url>
<layout>default</layout>
</repository>
</repositories>
3. Conclusion
Maven integration simplifies publishing and sharing the Mule connectors on Anypoint Exchange. It is possible to extend this to CI/CD pipelines using normal Maven deployment steps.
4. Reference
-
Exchange documentation
Stay updated!
On this blog, I post articles about different technologies like Java, MuleSoft, and much more.
You can get updates for new Posts in your email by subscribing to JavaStreets feed here -
Lives on Java Planet, Walks on Java Streets, Read/Writes in Java, JCP member, Jakarta EE enthusiast, MuleSoft Integration Architect, MuleSoft Community Ambassador, Open Source Contributor and Supporter, also writes at Unit Testers, A Family man!