This repository will not be updated. The repository will be kept available in read-only mode.
In this sample application, you will create a basic Java web application using Knative Eventing, Spring, and Cloudant. This starter kit provides a starting point for creating Java microservice applications that use Knative Eventing and Spring. The application includes a sample event source with Cron job source and displays events from this source to a web page. This application follows standard best practices, including a health check.
Capabilities are provided through dependencies in the pom.xml
file. The ports are set to the defaults of 8080
for http and 8443
for https and are exposed to the CLI in the cli-config.yml
file. The ports are set in the pom.xml
file and exposed to the CLI in the cli-config.yml
file.
You can deploy this application to IBM Cloud in a Knative-enabled cluster or build it locally by cloning this repo first. After your app is live, you can access the /health
endpoint to test your cloud native application.
Important: This application requires a Cloudant service to successfully pass all unit tests. See the IBM Cloud Catalog to provision a Cloudant service with the free Lite plan if you do not already have one. Also, the application and the Cron job event source must be deployed to a Knative-enabled Kubernetes cluster to support complete Knative Eventing functionality.
Click Deploy to IBM Cloud to deploy this same application to IBM Cloud. This option creates a deployment pipeline, complete with a hosted GitLab project and DevOps toolchain. You will have the option of deploying to either Code Engine or a Knative-enabled Kubernetes cluster. IBM Cloud DevOps services provide toolchains as a set of tool integrations that support development, deployment, and operations tasks inside IBM Cloud. Monitor the pipeline stages to ensure successful deployment.
After the application is successfully deployed, you can use the IBM Cloud CLI Developer Tools commands to deploy the Cron job event source to the same Kubernetes cluster.
-
Edit the
cronjob-source.yml
file to change thesink.name
property to the name of the application that will receive events. This name can be found in the.bluemix/service-knative.yaml
file as themetadata.name
property. -
Optionally, change the name
metada.name
property incronjob-source.yml
to change the name of the deployed event source. -
After the Developer Tools are installed and configured, run the following command:
kubectl apply -f cronjob-source.yml
Then visit the /events
endpoint to view events as they are generated by the Cron job event source. Events are stored in the bound Cloudant database service and can be deleted by visiting the /events?deleteAll=true
endpoint.
To get started building this application locally, you can either run the application natively or use the IBM Cloud CLI Developer Tools commands for containerization and easy deployment to IBM Cloud.
- Maven
- Java 8: Any compliant JVM should work.
- Java 8 JDK from Oracle
- Java 8 JDK from IBM (AIX, Linux, z/OS, IBM i), or Download a Liberty server package that contains the IBM JDK (Windows, Linux)
To build and run an application, you must have a Cloudant database service provisioned. Then do one of the following:
-
In the IBM Cloud console, navigate to the service's page. Under the Service Credentials tab of the service, select View Credentials and copy the username, password, and url values to your app's
application.properties
file as follows (or create the file undersrc/main/resources
if it does not exist):cloudant_username=62c520dc-9367... cloudant_password=8c03bd171cd99... cloudant_url=https://62c520dc-9367...cloudant.com
-
If the IBM Cloud CLI is installed, run the
ibmcloud dev get-credentials
command. This command downloads the service credentials into thesrc/main/resources/localdev-config.json
file, which is read by the application at runtime. This file is ignored by Git by default and should not be put into source control.
Then run the following commands:
mvn install
java -jar ./target/knative-eventing-1.0-SNAPSHOT.jar
To run an application in Docker, use the Docker file named Dockerfile
. If you do not want to install Maven locally, you can use Dockerfile-tools
to build a container with Maven installed.
You can also verify the state of your locally running application using the Selenium UI test script included in the scripts
directory.
Install the IBM Cloud CLI on your machine by running the following command:
curl -sL https://ibm.biz/idt-installer | bash
Create an application on IBM Cloud by running the following command:
ibmcloud dev create
This command creates and downloads a starter application with the files that are needed for local development and deployment.
Your application will be compiled with Docker containers.
To compile and run your app, run the following commands:
ibmcloud dev build
ibmcloud dev run
The build
and run
commands launch your application locally.
When you are ready to deploy to IBM Cloud on Kubernetes, run one of the following commands:
ibmcloud dev deploy -t container // to K8s cluster
You can build and debug your app locally by running the following commands:
ibmcloud dev build --debug
ibmcloud dev debug
This repository includes a .cracveomit
file that is used by Code Risk Analyzer (CRA) in IBM Cloud Continuous Delivery. This file helps address vulnerabilities that are found by CRA until a remediation is available, at which point the vulnerabilities will be addressed in the respective package versions. CRA keeps the code in this repository free of known vulnerabilities, and therefore helps make applications that are built on this code more secure. If you are not using CRA, you can safely ignore this file.
- Learn more about augmenting your Java applications on IBM Cloud with the Java Programming Guide.
- Explore other sample applications on IBM Cloud.
This sample application is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.