Code Monkey home page Code Monkey logo

springio-question-5's Introduction

Spring I/O - Question 5

This is question 5 of a game intended to demonstrate serverless and event-driven features on Kubernetes, using Knative and CloudEvents.

  • For more information on the game, visit this page.
  • For instructions on deploying the entire system, visit this page.

Question 5 is a Spring Boot project relying on Spring Cloud Function, Spring Native, and the CloudEvents Java SDK. The project has been initialized using the Knative func plugin.

Usage

$ http <url> player="jon-snow" sessionId="game-blahblah" optionA=false optionB=true optionC=false optionD=false remainingTime=13

HTTP/1.1 200 OK
Content-Length: 98
Content-Type: application/json
accept-encoding: gzip, deflate
connection: keep-alive
user-agent: HTTPie/3.1.0

{
    "player": "jon-snow"
    "level": "devoxxuk-question-5",
    "levelScore": 18,
    "sessionId": "game-blahblah",
    "gameTime": "2022-04-19T11:40:46.04108"
}

Local execution

Make sure you have a Java 17 distribution installed.

You can run the application locally as follows.

./gradlew bootRun

To run the tests run the following command.

./gradlew test

The func CLI

It's recommended to set the FUNC_REGISTRY environment variable.

export FUNC_REGISTRY=<registry>/<username>
echo "export FUNC_REGISTRY=<registry>/<username>" >> ~/.bashrc

where <registry> is a container registry URI (for example, ghcr.io) and username is your account name on that registry.

Building

This command builds an OCI image for the function. By default, this will build a GraalVM native image.

func build -v

Note: If you want to disable the native build, you need to edit the func.yaml file and remove (or set to false) the following BuilderEnv variable:

buildEnvs:
  - name: BP_NATIVE_IMAGE
    value: "true"

Running

This command runs the func locally in a container using the image created above.

func run

Deploying

This command will build and deploy the function into cluster.

func deploy -v

Function invocation

For the examples below, please be sure to set the URL variable to the route of your function.

You get the route by following command.

func info

Note the value of Routes: from the output, set $URL to its value.

TIP:

If you use kn then you can set the url by:

# kn service describe <function name> and show route url
export URL=$(kn service describe $(basename $PWD) -ourl)

Then, call the function as follows.

http $URL player="jon-snow" sessionId="game-blahblah" optionA=false optionB=false optionC=true optionD=false remainingTime=13

Cleanup

To clean the deployed function run:

func delete

springio-question-5's People

Contributors

thomasvitale avatar

Watchers

salaboy avatar James Cloos 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.