Coder Social home page Coder Social logo

ibm / knative-eventing-java-app Goto Github PK

View Code? Open in Web Editor NEW
2.0 10.0 8.0 232 KB

WARNING: This repository is no longer maintained

License: Apache License 2.0

Dockerfile 2.04% Java 94.73% Shell 1.27% Python 1.95%
knative knative-serving knative-eventing cloudant spring spring-boot

knative-eventing-java-app's Introduction

WARNING: This repository is no longer maintained โš ๏ธ

This repository will not be updated. The repository will be kept available in read-only mode.

IBM Cloud

IBM Cloud platform Apache 2

Create and deploy a Knative Eventing microservice in Java Spring

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.

Steps

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.

Deploying to IBM Cloud

Deploy to IBM Cloud

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.

  1. Edit the cronjob-source.yml file to change the sink.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 the metadata.name property.

  2. Optionally, change the name metada.name property in cronjob-source.yml to change the name of the deployed event source.

  3. 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.

Building locally

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.

Native application development

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 under src/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 the src/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:

  1. mvn install
  2. 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.

IBM Cloud CLI Developer Tools commands

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

CRA Scanning

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.

Next steps

License

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.

Apache License FAQ

knative-eventing-java-app's People

Contributors

christoc-ibm avatar chuckcox avatar dependabot[bot] avatar devexdev avatar gee4vee avatar jmeis avatar keithkade avatar nfstein avatar reedcozart avatar stevemar avatar youming-lin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.