The blog "Take Event APIs to where your Apigee APIs are ..." introduced an integration between the Google Apigee and Solace Platforms.
In this codelab we walk you through the steps that enable the developer experience for event APIs demonstrated in the blog.
The overall solution looks like this:
Let's look at all the components involved:
As you can see the interactions flow through the Apigee gateway as we chose to implement the integration completely in Apigee:
Head over to the blog to learn more if you haven't read it yet.
You need access to a Solace Cloud account - including Event Portal - and a PubSub+ Event Broker.
No problem if you haven't got that yet, simply follow step 3 in the A Solace Primer - Getting Started with Solace PubSub+ Event Broker codelab
You need to supply a Solace API Token to the API Proxies you'll deploy in Apigee.
Follow the steps at API Authentication in the Solace Platform API documentation to create the token and store it in a place that you can refer to it again.
You can always regenerate the API token if it gets lost.
If you haven't got a working Apigee environment you can go to the Apigee console and either start the free trial or use the "Setup with Defaults" option.
In the Google Cloud Console go to Service Accounts and create a new service account, name it "Apigee-eventportal-integration", add the "Apigee API Admin" role and save it.
Set up the Developer Portal via the Kickstart solution.
When launching the Kickstart, enable HTPS connectivity:
REST API calls in this codelab are given as curl commands.
You can use MQTT to test developer access to Event APIs on the Solace PubSub+ Broker - a suitable tool is MQTTX.
You can also use any other tool that you use to connect to Solace brokers.
You will use the Apigee-deploy-maven-plugin
to package API Proxies.
See the prerequisites for running the maven plugin in the README
git clone git@github.com:<YOUR_GITHUB_USER>/solace-Apigee-sample.git
cd solace-dev-codelabs
git checkout -b <BRANCH_NAME>
Duration 0:15:00
When viewing your Dev Portal deployment in the Google Cloud console click "CONFIGURE YOUR SITE" to finish the Dev Portal Setup
The steps to remove HTTP Basic Authentication are described on the deployment page of the Dev Portal in the Google Cloud Console.
The patch is contained in the github repo you cloned earlier in the folder asyncapi-patch
.
Connect to one of the portal VMs in the Kickstart Deployment using SSH - you cna do this form within the Google Compute Engine console.
asyncapi.patch
file from the location given above to the home directory on one of the the Kickstart VMs$> cd /var/www/devportal/code/web/modules/contrib/apigee_api_catalog
$> sudo patch -p1 < ~/asyncapi.patch
.In the Dev Portal admin user interface enable the "AsyncAPI" module (if not already enabled):
We need to patch the Apigee Platform API so the Developer Portal URL to point to API Proxy setup. You need to amend ClientInterface.php
in /var/www/devportal/code/vendor/apigee/apigee-client-php/src/
.
Please replace the link to googleapis.com
with a link to your Apigee API Gateway in line 57 and line 64
Original ClientInterface.php
line 57-46:
public const HYBRID_ENDPOINT = 'https://apigee.googleapis.com/v1';
/**
* Default endpoint for Apigee Management API on GCP
*
* @var string
*/
public const APIGEE_ON_GCP_ENDPOINT = 'https://apigee.googleapis.com/v1';
Example of amended ClientInterface.php
:
public const HYBRID_ENDPOINT = 'https://34.54.13.157.nip.io/v1';
/**
* Default endpoint for Apigee Management API on GCP
*
* @var string
*/
public const APIGEE_ON_GCP_ENDPOINT = 'https://34.54.13.157.nip.io/v1';
The integration with Event Portal requires that Apigee Dev Portal REST APIs are enabled to interact with API Docs. Please follow all the steps in this guide up to and including "Create a new role and a service account".
When you follow the steps to install the Drupal patch and module:
/var/www/devportal/code/composer.json
JSON:API Extras
and HTTP Basic Authentication
node--asyncapi_doc
resource is enabled. (see screenshot below) Duration 0:10:00
You can either import API Proxies from API Proxy Bundles or use the Apigee-deploy-maven-plugin to build and deploy the API Proxies.
You need to build and deploy the API proxies found in src/gateway
within the repository:
src/gateway/Apigee-Platform-Proxy
src/gateway/EventPortalIntegration
src/gateway/hello
src/gateway/OAuth
The hello
proxy is optional, its purpose is to demonstrate use of the same access token / JWT for authn and authz across REST and Event APIs.
For each of the API Proxies listed above:
$> cd <CLONED_REPO_ROOT>/src/gateway/<API_PROXY_DIRECTORY>
$> mvn package
Replace < CLONED_REPO_ROOT >
with the location of the cloned repo and < API_PROXY_DIRECTORY >
with the directory of the API Proxy as listed in the previous section.
You'll find the zipped API Proxy Bundle for upload to Apigee in < CLONED_REPO_ROOT >/src/gateway< API_PROXY_DIRECTORY >/target
See the readme for full instructions on how to use the maven plugin for deployment to Apigee.
For each of the API Proxies listed above:
$> cd <CLONED_REPO_ROOT>/src/gateway/<API_PROXY_DIRECTORY>
$> mvn install
Replace < CLONED_REPO_ROOT >
with the location of the cloned repo and < API_PROXY_DIRECTORY >
with the directory of the API Proxy as listed in the previous section.
First generate private and public key and a JSON Web Key.
There are multiple web tools that can do this
First upload the PRIVATE_KEY
that you just created:
curl --location 'https://<API_GATEWAY_HOSTNAME>/oauth/keys' \
--header 'Content-Type: text/plain' \
--data '<PRIVATE_KEY>'
Then upload the JWK
:
curl --location 'https://<API_GATEWAY_HOSTNAME>/oauth/jwks' \
--header 'Content-Type: application/json' \
--data '<JWK>'
You have created the API Token in the "Prerequisites" section, it is referred to as API_TOKEN
in the command below:
curl --location 'https://<API_GATEWAY_HOSTNAME>/ep-bootstrap/token' \
--header 'Content-Type: text/plain' \
--data '<API_TOKEN'
When you are importing Event API Products this API Proxy also uploads the associated AsyncAPI specs to the Apigee Dev Portal - you'll need to supply the endpoint and credentials for this connection.
curl --location 'https://<API_GATEWAY_HOSTNAME>/ep-bootstrap/devportal' \
--header 'Content-Type: application/json' \
--data '{
"host": "https://<DEV_PORTAL_HOST>",
"user": "<DEV_PORTAL_API_USER?",
"password":"<DEV_PORTAL_API_PASSWORD>"
}'
You have created a user when you configured the Dev Portal. Replace < DEV_PORTAL_API_USER >
and < DEV_PORTAL_API_PASSWORD >
with the user credentials.
DEV_PORTAL_HOST
refers to the public host name that was assigned to your Dev Portal when you ran the Kickstart deployment.
Once you have access to Event Portal you'll need to do some initial configuration and create some assets:
Follow the steps described here
You can skip steps if you already have created some of these objects - such as schemas, events- in Event Portal that you intend to reuse.
The sample domain is stored in the github repo that you have cloned. It's calles retail-demo.json
and is located in the eventportal
directory.
Follow the instructions to import an Application Domain into Event Portal.
Once you have an Event API Product - either imported or designed by you - you need to assign it to an environment and make it visible to APIM solutions: see Make Event API Products Publicly Available in the Solace Platform API documentation.
Retrieve a list of importable API Products (i.e. Event API Product Plans):
curl --location 'https://<API_GATEWAY_HOSTNAME>/ep-bootstrap/eventApiProducts?where=applicationDomainId%3D%3Dgfjt1r5b8db'
Pick an API Product from the importableApiProducts
element of the response you retrieved in the previous step and use it in the command below. Set --data
payload replacing < IMPORTABLE_API_PRODUCT >
:
curl --location 'https://<API_GATEWAY_HOSTNAME>/ep-bootstrap/eventApiProducts' \
--header 'Content-Type: application/json' \
--data '<IMPORTABLE_API_PRODUCT>'
For example:
curl --location 'https://<API_GATEWAY_HOSTNAME>/ep-bootstrap/eventApiProducts' \
--header 'Content-Type: application/json' \
--data '{
"apiProductName": "Order Event API-default",
"planId": "u3r88l0pxk7",
"eventApiProductId": "rezt2caps5s"
}'
The blog "Take Event APIs to where your Apigee APIs are ..." walks you through the developer experience in more detail.
The Event API Product that we imported from Solace Event Portal is listed on API Product
You need admin access to the Solace PubSub+ broker as you set up an OAuth provider in the broker in this section. This enables developers to use JWT issued by Apigee to connect to the broker.
Prerequisites to follow the MQTT connection steps:
Follow the steps on Configuring an Event Broker Service to Use OAuth Identity Provider Authorization
The OAuth Profile should look like the screenshot below, please note:
< OAUTH_PROFILE_NAME >
https://< API_GATEWAY_HOSTNAME >/oauth/jwks
Use the credentials associated with the app you created in the Developer Portal:
CLIENT_ID
: the app's consumer keyCLIENT_SECRET
: the app's consumer secretExchange your credentials for an access token:
curl --location 'https://<API_GATEWAY_HOSTNAME>/oauth/jwt' \
--header 'Content-Type: application/x-www-form-urlencoded' \
-u '<CLIENT_ID>:<CLIENT_SECRET>' \
--data-urlencode 'grant_type=client_credentials'
Save the value of the access_token
element of the response. You need it for your establishing the MQTT connection, we refer to it later as TOKEN
.
You also need the broker URL and you might want to test that you can start a subscription (receive) once connected. All of this information is contained in the AsyncAPI spec available on the Developer Portal:
MQTTS_URL
belowMQTT_TOPIC
belowThe screenshot below highlights examples for the values you need to take note of:
Start MQTTX (you can use another MQTT client that you prefer and are familiar with) and configure a new connection.
Use the following values in the connection details:
mqtts://
option (if you use a secure MQTT port)MQTTS_URL
MQTTS_URL
OAUTH~< OAUTH_PROFILE_NAME >~< TOKEN >
Once connected add a subscription, use MQTT_TOPIC
and replace any variables - enclosed in "{}""}" with suitable values or MQTT wildcards.
Congratulations, you now have a working custom integration between Google Apigee and Solace.
Thanks for participating in this codelab! Let us know what you thought in the Solace Community Forum! If you found any issues along the way we'd appreciate it if you'd raise them by clicking the Report a mistake button at the bottom left of this codelab.