Skip to content

Commit 418df20

Browse files
committed
better readme.md
1 parent 31e730a commit 418df20

File tree

4 files changed

+189
-7
lines changed

4 files changed

+189
-7
lines changed

micro-client/readme.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22

33
[micro-client example apps](https://github.com/aol/micro-server/tree/master/micro-client/src/test/java/app)
44

5-
This plugin provides two REST Clients
5+
This plugin provides thre REST Clients
66

7-
1. NIORestClient - which is a non-blocking REST client using NIO
8-
2. AsyncRestClient - which is asyncrhonous, but makes use of threads
7+
1. NIORestClient - which is a non-blocking REST client using NIO, wrapper over Apache Async HTTP. Modified to return Java 8 CompletableFuture objects.
8+
2. AsyncRestClient - a wrapper over the Async Jersey Rest Client (it is asyncrhonous, but makes use of threads rather than NIO). Modified to return Java 8 CompletableFuture objects, and enhanced with withXXXX methods for configuration purposes.
9+
3. RestClient - which syncrhonous wrapper over the Jersey Rest Client, enhanced with withXXXX methods for configuration purposes
910

10-
The NIORestClient is available as Spring bean. AsyncRestClient can simply be instantiated via the new keyword.
11+
The NIORestClient is available as Spring bean. AsyncRestClient & RestClient can simply be instantiated via the new keyword.
1112

12-
## Example
13+
## Example AsyncRestClient
1314
```java
1415
public class Example{
1516

1617

17-
18-
private final AsyncRestClient<Result> restClient;
18+
private final int readTimeout = 10_000;
19+
private final int connnectionTimeout = 1_000;
20+
private final AsyncRestClient<Result> restClient = new AsyncRestClient<>(readTimeout,connectionTimeout);;
1921
private final String url;
2022
private final String ACCEPT_HEADERS;
2123
private final String CONTENT_HEADERS;
@@ -30,6 +32,30 @@ public class Example{
3032
}
3133

3234

35+
}
36+
```
37+
## Example RestClient
38+
```java
39+
public class Example{
40+
41+
42+
private final int readTimeout = 10_000;
43+
private final int connnectionTimeout = 1_000;
44+
private final RestClient<Result> restClient = new RestClient<>(readTimeout,connectionTimeout);
45+
private final String url;
46+
private final String ACCEPT_HEADERS;
47+
private final String CONTENT_HEADERS;
48+
49+
public Result query(Payload payload){
50+
51+
return this.restClient.withAccept(ACCEPT_HEADERS)
52+
.withContentType(CONTENT_HEADERS)
53+
.withResponse(RESULT.class)
54+
.post(url,payload);
55+
56+
}
57+
58+
3359
}
3460
```
3561
## To use

micro-javaslang/readme.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This plugin
1111
a. JavaslangReactive mixin allows creating Javaslang reactive-streams Publishers and Subsribers simple
1212
b. JavaslangPipes and JavaslangReactive provide integration with simple-react
1313
c. Ability to push data into a Javaslang Stream across threads via JavaslangPipes
14+
15+
1416
1517

1618
## To use
@@ -31,3 +33,86 @@ Gradle
3133

3234
compile 'com.aol.microservices:micro-javaslang:x.yz'
3335

36+
## Examples
37+
38+
JavaslangPipes
39+
40+
```java
41+
42+
Queue queue = QueueFactories.boundedNonBlockingQueue(1000); //set up an Agrona backed wait-free queue
43+
queue.add("world"); //add some data to the queue
44+
JavaslangPipes.register("myQueue",queue); //register the queue
45+
46+
//on a separate thread process data streaming from the queue
47+
JavaslangPipes.stream("myQueue")
48+
.map(this:process)
49+
.forEach(this:save);
50+
51+
```
52+
53+
Simple App with Javaslang Lists and Sets
54+
55+
```java
56+
@Microserver
57+
@Path("/javaslang")
58+
@Rest
59+
public class JavaslangApp {
60+
61+
62+
public static void main(String[] args){
63+
new MicroserverApp(() -> "javaslang-app").start();
64+
65+
}
66+
67+
68+
@GET
69+
@Produces("application/json")
70+
@Path("/ping")
71+
public ImmutableJavaslangEntity ping() {
72+
return ImmutableJavaslangEntity.builder().value("value")
73+
.list(List.ofAll("hello", "world"))
74+
.mapOfSets(HashMap.<String,Set>empty().put("key1",HashSet.ofAll(Arrays.asList(1, 2, 3))))
75+
.build();
76+
}
77+
78+
79+
@XmlAccessorType(XmlAccessType.FIELD)
80+
@XmlType(name = "")
81+
@XmlRootElement(name = "immutable")
82+
@Getter
83+
@AllArgsConstructor
84+
@Builder
85+
public static class ImmutableJavaslangEntity {
86+
87+
private final String value;
88+
private final List<String> list;
89+
private final Map<String,Set> mapOfSets;
90+
91+
92+
public ImmutableJavaslangEntity() {
93+
this(null,null,null);
94+
}
95+
96+
}
97+
98+
}
99+
```
100+
101+
Running the app and browsing to http://localhost:8080/javaslang-app/javaslang/ping
102+
103+
```json
104+
{
105+
"value": "value",
106+
"list": [
107+
"hello",
108+
"world"
109+
],
110+
"mapOfSets": {
111+
"key1": [
112+
1,
113+
2,
114+
3
115+
]
116+
}
117+
}
118+
```
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package app.example.javaslang;
2+
3+
import java.util.Arrays;
4+
5+
import javaslang.collection.HashMap;
6+
import javaslang.collection.HashSet;
7+
import javaslang.collection.List;
8+
import javaslang.collection.Map;
9+
import javaslang.collection.Set;
10+
11+
import javax.ws.rs.GET;
12+
import javax.ws.rs.Path;
13+
import javax.ws.rs.Produces;
14+
import javax.xml.bind.annotation.XmlAccessType;
15+
import javax.xml.bind.annotation.XmlAccessorType;
16+
import javax.xml.bind.annotation.XmlRootElement;
17+
import javax.xml.bind.annotation.XmlType;
18+
19+
import lombok.AllArgsConstructor;
20+
import lombok.experimental.Builder;
21+
import lombok.Getter;
22+
23+
import com.aol.micro.server.MicroserverApp;
24+
import com.aol.micro.server.auto.discovery.Rest;
25+
import com.aol.micro.server.config.Microserver;
26+
27+
@Microserver
28+
@Path("/javaslang")
29+
@Rest
30+
public class JavaslangApp {
31+
32+
33+
public static void main(String[] args){
34+
new MicroserverApp(() -> "javaslang-app").start();
35+
36+
}
37+
38+
39+
@GET
40+
@Produces("application/json")
41+
@Path("/ping")
42+
public ImmutableJavaslangEntity ping() {
43+
return ImmutableJavaslangEntity.builder().value("value")
44+
.list(List.ofAll("hello", "world"))
45+
.mapOfSets(HashMap.<String,Set>empty().put("key1",HashSet.ofAll(Arrays.asList(1, 2, 3))))
46+
.build();
47+
}
48+
49+
50+
@XmlAccessorType(XmlAccessType.FIELD)
51+
@XmlType(name = "")
52+
@XmlRootElement(name = "immutable")
53+
@Getter
54+
@AllArgsConstructor
55+
@Builder
56+
public static class ImmutableJavaslangEntity {
57+
58+
private final String value;
59+
private final List<String> list;
60+
private final Map<String,Set> mapOfSets;
61+
62+
63+
public ImmutableJavaslangEntity() {
64+
this(null,null,null);
65+
}
66+
67+
}
68+
69+
}

micro-javaslang/src/test/java/com/aol/micro/server/reactive/JavaslangPipesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import com.aol.micro.server.javaslang.reactive.JavaslangPipes;
1616
import com.aol.simple.react.async.Queue;
17+
import com.aol.simple.react.async.factories.QueueFactories;
1718
import com.aol.simple.react.stream.traits.LazyFutureStream;
1819

1920
public class JavaslangPipesTest {
@@ -34,6 +35,7 @@ public void testGetPresent() {
3435

3536
@Test
3637
public void testStream() {
38+
3739
Queue queue = new Queue();
3840
queue.add("world");
3941
JavaslangPipes.register("hello",queue);

0 commit comments

Comments
 (0)