Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Run JAX-RS applications on Fn using JRestless

NotificationsYou must be signed in to change notification settings

fnproject/fn-jrestless-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Author:Rae Jeffries-Harris

This is an example JAX-RS app that can be deployed on the Fn platform.

What?

JRestless allows you to create FaaS applications usingJAX-RS.We are addingsupport for using JRestless on Fn.

This means you can use all the JAX-RS features you're used to,@Path,@GET,@QueryParam -all the marshalling and content-types, all the routing. All of it, in a FaaS function. JRestless usesJersey internally so you have the full capability of the reference JAX-RSimplementation.

If you take advantage ofFnProject's Hot Functionsyou can build a responsive application which only runs when it's needed.

This project is an example of how to use JRestless build a JAX-RS app on FnProject.

How does it work?

The code incom.example.fnjrestless.blog is a JAX-RS app:

  • BloggingResource.java - defines the routes
  • BloggPost.java - POJO domain object
  • BlogStore.java - Database connection code
  • BloggingApp.java - 5 lines of code to point JRestless at our app

Check out the code, then in the root of the project run:

$ fn build...snip...Function raej/jrest:0.0.4 built successfully.

Make sure you have an fn server running (Seethe tutorial - TL;DRfn start)

Then create your app:

$ fn apps create jaxrsSuccessfully created app:  jaxrs$ fn deploy --app jaxrs --local

You will need a database, easy way is to run the./start-mysql.sh included in the repo.

Some config for your app:

## The IP address of the host from inside a container$export DOCKER_HOST_IP=$(docker inspect --type container -f'{{.NetworkSettings.Gateway}}' fnserver)fn apps configset jaxrs DB_URL"jdbc:mysql://${DOCKER_HOST_IP}/POSTS"fn apps configset jaxrs DB_DRIVER com.mysql.jdbc.Driverfn apps configset jaxrs DB_USER jaxrsfn apps configset jaxrs DB_PASSWORD SgRoV3s

Map the routes used by the app to the function:(use whichever image version was published in the previous deploy )

fn routes create jaxrs /route/html --image raej/jrest:0.0.2fn routes create jaxrs /route/blogs --image raej/jrest:0.0.2# fn routes create jaxrs /route/add  <-- this was added by `fn deploy` earlier

All 3 of these routes will point to the same container image.

Bask in the glory of your creation

Browse tohttp://localhost:8080/r/jaxrs/route/html to see the blog's UI.

There is a simple HTML page served from/html, which fetches data from/blogs and posts new blog entries to/add.

FAQ / Notes

QUESTION: How many Function containers will be used?

Fn treats each route independently, so there will beat least one per endpoint that you use. There may be more than one, as container instances will be created dynamically to cope with high load.

QUESTION: What about binding variables from path params?

Fn currently does not support wildcards in routes. Issues#170 and#256 track current proposals to fix this.

About

Run JAX-RS applications on Fn using JRestless

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp