mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-25 12:46:44 +00:00
Add exampleSite
This commit is contained in:
parent
7a6ab6d724
commit
5b7db23aaa
18
exampleSite/config.yml
Normal file
18
exampleSite/config.yml
Normal file
@ -0,0 +1,18 @@
|
||||
baseURL: http://example.org
|
||||
title: Rx Jersey
|
||||
theme: book
|
||||
|
||||
# Book configuration
|
||||
disablePathToLower: true
|
||||
|
||||
params:
|
||||
# show or hide table of contents for page
|
||||
BookShowToC: true
|
||||
|
||||
# Set bundle to render side menu
|
||||
# if not specified file structure and weights will be used
|
||||
BookMenuBundle: /menu
|
||||
|
||||
# specify section of content to render as menu
|
||||
# if bookMenuBundle is not set, 'docs' is value by default
|
||||
BookSection: docs
|
77
exampleSite/content/_index.md
Normal file
77
exampleSite/content/_index.md
Normal file
@ -0,0 +1,77 @@
|
||||
---
|
||||
title: Introduction
|
||||
type: docs
|
||||
---
|
||||
|
||||
# RxJersey - Reactive Jersey Feature
|
||||
|
||||
[![Build Status](https://travis-ci.org/alex-shpak/rx-jersey.svg?branch=master)](https://travis-ci.org/alex-shpak/rx-jersey)
|
||||
![Maven Central](https://img.shields.io/maven-central/v/net.winterly.rxjersey/core-server.svg)
|
||||
|
||||
RxJersey is RxJava extension for [Jersey](https://jersey.java.net/) framework providing non-blocking Jax-RS server and client.
|
||||
RxJersey target is to handle large amount requests in small static set of threads, which is highly suitable for microservice applications.
|
||||
|
||||
Library uses Jersey 2 async support with `@Suspended` and `AsyncResponse` under the hood.
|
||||
|
||||
## Features
|
||||
- [x] RxJava Support
|
||||
- [x] RxJava 2 Support
|
||||
- [x] RxJava Proxy Client
|
||||
- [x] Async Request Interceptors
|
||||
- [x] Dropwizard bundle
|
||||
|
||||
## Roadmap
|
||||
- [ ] Futures support
|
||||
- [ ] Vert.x integration
|
||||
- [ ] Improved proxy client
|
||||
|
||||
|
||||
## Maven Artifacts
|
||||
### Maven Central
|
||||
```
|
||||
compile "net.winterly.rxjersey:dropwizard:$rxJerseyVersion"
|
||||
compile "net.winterly.rxjersey:rxjava-client:$rxJerseyVersion"
|
||||
compile "net.winterly.rxjersey:rxjava-server:$rxJerseyVersion"
|
||||
compile "net.winterly.rxjersey:rxjava2-client:$rxJerseyVersion"
|
||||
compile "net.winterly.rxjersey:rxjava2-server:$rxJerseyVersion"
|
||||
```
|
||||
|
||||
### JitPack
|
||||
Most recent snapshot is available via [JitPack](https://jitpack.io/#alex-shpak/rx-jersey/)
|
||||
```
|
||||
compile "com.github.alex-shpak.rx-jersey:dropwizard:$rxJerseyVersion"
|
||||
compile "com.github.alex-shpak.rx-jersey:rxjava-client:$rxJerseyVersion"
|
||||
compile "com.github.alex-shpak.rx-jersey:rxjava-server:$rxJerseyVersion"
|
||||
compile "com.github.alex-shpak.rx-jersey:rxjava2-client:$rxJerseyVersion"
|
||||
compile "com.github.alex-shpak.rx-jersey:rxjava2-server:$rxJerseyVersion"
|
||||
```
|
||||
|
||||
|
||||
## Example
|
||||
```java
|
||||
@Path("/example/")
|
||||
public class GithubResource {
|
||||
|
||||
@Remote("https://api.github.com/")
|
||||
private GithubApi githubApi;
|
||||
|
||||
@GET
|
||||
@Path("github")
|
||||
public Single<GithubRepository> getRepository() {
|
||||
return githubApi.getRepository("alex-shpak", "rx-jersey").toSingle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Path("/")
|
||||
public interface GithubApi {
|
||||
|
||||
@GET
|
||||
@Path("/repos/{user}/{repo}")
|
||||
Observable<GithubRepository> getRepository(@PathParam("user") String username, @PathParam("repo") String repo);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Licence
|
||||
[MIT](LICENCE.txt)
|
35
exampleSite/content/docs/dropwizard-configuration.md
Normal file
35
exampleSite/content/docs/dropwizard-configuration.md
Normal file
@ -0,0 +1,35 @@
|
||||
## Dropwizard configuration
|
||||
|
||||
Use provided `RxJerseyBundle`
|
||||
```java
|
||||
@Override
|
||||
public void initialize(Bootstrap<RxJerseyConfiguration> bootstrap) {
|
||||
bootstrap.addBundle(new RxJerseyBundle<RxJerseyConfiguration>()
|
||||
.setClientConfigurationProvider(config -> config.client)
|
||||
.register(HeaderInterceptor.class)
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Alternatively you can directly configure and register Jersey feature
|
||||
```java
|
||||
public void run(RxJerseyConfiguration configuration, Environment environment) throws Exception {
|
||||
JerseyEnvironment jersey = environment.jersey();
|
||||
|
||||
Client client = new JerseyClientBuilder(environment)
|
||||
.using(configuration.client)
|
||||
.using(new GrizzlyConnectorProvider())
|
||||
.buildRx("Client", RxObservableInvoker.class);
|
||||
|
||||
RxJerseyServerFeature rxJerseyServerFeature = new RxJerseyServerFeature()
|
||||
.register(HeaderInterceptor.class);
|
||||
|
||||
RxJerseyClientFeature rxJerseyClientFeature = new RxJerseyClientFeature()
|
||||
.register(client);
|
||||
|
||||
jersey.register(rxJerseyServerFeature);
|
||||
jersey.register(rxJerseyClientFeature);
|
||||
}
|
||||
```
|
||||
|
||||
#### [See example](https://github.com/alex-shpak/rx-jersey/tree/master/example) for more information
|
20
exampleSite/content/docs/jersey-configuration.md
Normal file
20
exampleSite/content/docs/jersey-configuration.md
Normal file
@ -0,0 +1,20 @@
|
||||
## Jersey configuration
|
||||
### Simple configuration
|
||||
This will assume default configuration with no interceptor and Grizzly client
|
||||
```java
|
||||
resourceConfig.register(RxJerseyServerFeature.class);
|
||||
resourceConfig.register(RxJerseyClientFeature.class);
|
||||
```
|
||||
|
||||
### Detailed configuration
|
||||
This configuration will add async request interceptor and override default client
|
||||
```java
|
||||
RxJerseyServerFeature rxJerseyServerFeature = new RxJerseyServerFeature()
|
||||
.register(AuthRequestInterceptor.class);
|
||||
|
||||
RxJerseyClientFeature rxJerseyClientFeature = new RxJerseyClientFeature()
|
||||
.register(client); // Should be non-blocking client implementation
|
||||
|
||||
resourceConfig.register(rxJerseyServerFeature);
|
||||
resourceConfig.register(rxJerseyClientFeature);
|
||||
```
|
60
exampleSite/content/docs/rx-jersey-client.md
Normal file
60
exampleSite/content/docs/rx-jersey-client.md
Normal file
@ -0,0 +1,60 @@
|
||||
## RxJersey Proxy Client
|
||||
|
||||
Proxy client provides convenient way to call resources without constructing request. Also it allows to reuse resource interfaces between microservices.
|
||||
|
||||
In order to enable RxJava in proxy client register Jersey feature
|
||||
```java
|
||||
RxJerseyClientFeature rxJerseyClientFeature = new RxJerseyClientFeature()
|
||||
.register(client); //should be non-blocking client implementation
|
||||
resourceConfig.register(rxJerseyClientFeature);
|
||||
```
|
||||
Default client with Grizzly connector will be used if not provided
|
||||
|
||||
|
||||
## Remote resource injection
|
||||
You can inject proxy client with `@Remote` annotation, in addition you can inject `WebTarget` or `RxWebTarget`
|
||||
```java
|
||||
@Path("/example/")
|
||||
public class GithubResource {
|
||||
|
||||
@Remote("https://api.github.com/")
|
||||
private GithubApi githubApi;
|
||||
|
||||
@Remote("https://api.github.com/")
|
||||
private WebTarget webTarget;
|
||||
|
||||
@GET
|
||||
@Path("github")
|
||||
public Single<GithubRepository> getRepository() {
|
||||
return githubApi.getRepository("alex-shpak", "rx-jersey").toSingle();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Manual proxy client creation
|
||||
You can use `WebResourceFactory` from `net.winterly.rxjersey.client` package in order to create proxy client
|
||||
|
||||
#### RxJava
|
||||
```java
|
||||
WebResourceFactory.newResource(
|
||||
ResourceInterface.class,
|
||||
rxWebTarget,
|
||||
new ObservableClientMethodInvoker()
|
||||
);
|
||||
```
|
||||
#### RxJava 2
|
||||
```java
|
||||
WebResourceFactory.newResource(
|
||||
ResourceInterface.class,
|
||||
webTarget,
|
||||
new FlowableClientMethodInvoker()
|
||||
);
|
||||
```
|
||||
|
||||
## Url resolving
|
||||
Below is example of URL merging based on `@Remote` annotation value
|
||||
|
||||
| Annotation Value | Jersey Context Path | Result URL |
|
||||
| ----------------------------- | --------------------------- | ---------------------------- |
|
||||
| @Remote("http://example.com") | http://baseurl.com/resource | http://example.com/ |
|
||||
| @Remote("/resource/") | http://baseurl.com/some | http://baseurl.com/resource/ |
|
64
exampleSite/content/docs/rx-jersey-server.md
Normal file
64
exampleSite/content/docs/rx-jersey-server.md
Normal file
@ -0,0 +1,64 @@
|
||||
## Jersey Server
|
||||
Register `RxJerseyServerFeature` in `resourceConfig`
|
||||
```java
|
||||
resourceConfig.register(RxJerseyServerFeature.class);
|
||||
```
|
||||
Or with configuration
|
||||
```java
|
||||
RxJerseyServerFeature rxJerseyServerFeature = new RxJerseyServerFeature()
|
||||
.register(AuthInterceptor.class);
|
||||
|
||||
resourceConfig.register(rxJerseyServerFeature);
|
||||
```
|
||||
|
||||
Update your resource adding rx return type:
|
||||
```java
|
||||
@Path("/")
|
||||
public class HelloResource {
|
||||
|
||||
@GET
|
||||
public Single<HelloEntity> getAsync() {
|
||||
return Single.just(new HelloEntity());
|
||||
}
|
||||
|
||||
|
||||
public static class HelloEntity {
|
||||
public String hello = "world";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Inteceptor
|
||||
You can use RxJava enabled interceptors. Result of such interceptor will be ignored. Thrown or returned error would be redirected to jersey.
|
||||
|
||||
#### RxJava
|
||||
```java
|
||||
public class SimpleInterceptor implements ObservableRequestInterceptor<Void> {
|
||||
public Observable<Void> intercept(ContainerRequestContext requestContext) {
|
||||
return Observable.empty();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### RxJava 2
|
||||
```java
|
||||
public class SimpleInterceptor implements CompletableRequestInterceptor {
|
||||
public Completable intercept(ContainerRequestContext requestContext) {
|
||||
return Observable.complete();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Important notes
|
||||
#### RxJava
|
||||
- It's recommended to use `rx.Single` as return type (Representing single response entity).
|
||||
- Multiple elements emitted in `Observable` will be treated as error.
|
||||
- Empty `Observable` or `null` value in `Observable` or `Single` will be treated as `204: No content`.
|
||||
- `Completable` will be executed and `204: No content` will be returned.
|
||||
|
||||
#### RxJava 2
|
||||
- It's recommended to use `io.reactivex.Maybe` which could be 0 or 1 item or an error.
|
||||
- Multiple elements emitted in `Observable` or `Flowable` will be treated as error.
|
||||
- Empty `Observable`/`Maybe` will be treated as `204: No content`.
|
||||
- `Completable` will be executed and `204: No content` will be returned.
|
12
exampleSite/content/menu/index.md
Normal file
12
exampleSite/content/menu/index.md
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
headless: true
|
||||
---
|
||||
|
||||
- [**Introduction**](/)
|
||||
- [Configuration](/docs/jersey-configuration)
|
||||
- [Jersey configuration](/docs/jersey-configuration)
|
||||
- [Dropwizard configuration](/docs/dropwizard-configuration)
|
||||
- **Usage**
|
||||
- [Server](/docs/rx-jersey-server)
|
||||
- [Client](/docs/rx-jersey-client)
|
||||
- Vert.x Integration
|
7
static/css/grids-responsive-min.css
vendored
7
static/css/grids-responsive-min.css
vendored
File diff suppressed because one or more lines are too long
11
static/css/pure-min.css
vendored
11
static/css/pure-min.css
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user