Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit 1decf70

Browse files
committed
readme 업데이트
1 parent 8c74d6c commit 1decf70

File tree

1 file changed

+98
-28
lines changed

1 file changed

+98
-28
lines changed

README.md

Lines changed: 98 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,30 @@
22
[ ![Download](https://api.bintray.com/packages/jdekim43/maven/rxjava-websocket-client/images/download.svg?version=0.0.1) ](https://bintray.com/jdekim43/maven/rxjava-websocket-client/0.0.1/link)
33

44

5-
### 주요기능
6-
* 자유로운 HttpClient : 모든 HttpClient 에서 동작할 수 있습니다. (Connection/ConnectionFactory 구현, OkHttp 는 OkHttpConnectionFactory 를 통해 바로 사용할 수 있습니다.)
7-
* 자유로운 메시지 형식 및 클래스 매핑 : json/xml/PlainString 등 자유로운 메시지 형식에 자유롭게 파서/매퍼를 설정할 수 있습니다. (InboundParser/OutboundSerializer 구현)
8-
* 하나의 Connection Inbound 스트림의 채널 및 커스텀 필터를 이용한 Observable 분리
9-
* LazyConnection : 구독하는 스트림이 있거나 sendMessage 요청시 WebSocket Connection 을 맺음 (모든 스트림이 dispose 되면 disconnect. 단, sendMessage 로 요청 후 dispose 되는 스트림이 없을 경우 disconnect 되지 않음.)
5+
### Features
6+
* Usable any TCP Client : OkHttp, etc...
7+
     OkHttp is implemented
8+
* Acceptable any message type based on String : JSON, XML, TEXT
9+
     Implementation of InboundParser and OutboundSerializer is required.
10+
* Fabricable 'Observable' which makes 'received message' events you need by using channel and filters.
1011

1112

12-
### 의존 라이브러리
13-
* RxJava2
13+
### Dependency
14+
* RxJava2
15+
* OkHttp (Optional)
1416

1517

16-
### 사용방법
17-
##### 설치
18-
##### maven
19-
```
20-
<dependency>
21-
<groupId>kr.jadekim.rxjava</groupId>
22-
<artifactId>rxjava-websocket-client</artifactId>
23-
<version>0.0.1</version>
24-
<type>pom</type>
25-
</dependency>
26-
```
27-
##### gradle
18+
### Install
2819
```
2920
compile "kr.jadekim.rxjava:rxjava-websocket-client:$version"
30-
or
21+
22+
//or
23+
3124
implementation "kr.jadekim.rxjava:rxjava-websocket-client:$version"
3225
```
3326

34-
##### 인터페이스 정의
27+
### Define client interface
28+
#### Use builder class
3529
```
3630
public interface TestClient {
3731
@@ -69,34 +63,101 @@ public interface TestClient {
6963
Completable stopNumber2(@Name("interval") int interval,
7064
@Name("startNumber") int startNumber);
7165
72-
// 메소드 명을 'disconnect' 로 하고 인스턴스로 만들어 호출 시 웹소켓 연결을 끊음.
66+
// If method name is 'disconnect', it will be working 'disconnect' action
7367
void disconnect();
7468
}
7569
```
70+
```
71+
JWebSocket webSocketClientFactory = new JWebSocket.Builder().build();
72+
TestClient client = webSocketClientFactory.create(TestClient.class, "ws://localhost/ws");
73+
client.subscribeAll().subscribe(msg -> System.out.println(msg));
74+
```
75+
76+
#### Use annotation
77+
```
78+
@WebSocketClient(
79+
url = "wss://echo.websocket.org"
80+
)
81+
public interface TestClient {...}
82+
83+
TestClient client = JWebSocket.create(TestClient.class);
84+
```
85+
7686

77-
##### ConnectionFactory 생성
87+
### Customize
88+
#### Customize ConnectionFactory (Customize TCP Client)
89+
```
90+
public class OkHttpConnectionFactory implements ConnectionFactory {
91+
...
92+
public OkHttpConnectionFactory(OkHttpClient okHttpClient) {
93+
...
94+
}
95+
96+
@Override
97+
public Connection connect(String url, boolean isErrorPropagation, WebSocketEventListener listener) {
98+
...
99+
}
100+
}
101+
```
78102
```
79103
OkHttpClient httpClient = new OkHttpClient();
80104
ConnectionFactory connectionFactory = new OkHttpConnectionFactory(httpClient);
81105
```
82106

83-
##### Parser/Serialiser 구현
107+
#### Customize Inbound Message Parser
108+
```
109+
public abstract class GsonInboundParser implements InboundParser<JsonElement> {
110+
...
111+
public GsonInboundParser(Gson gson) {
112+
...
113+
}
114+
115+
public abstract String getChannelName(JsonElement data);
116+
117+
@Override
118+
public Inbound<JsonElement> parse(String message) {
119+
...
120+
}
121+
122+
@Override
123+
public <Model> Model mapping(JsonElement object, Type modelType) {
124+
...
125+
}
126+
}
127+
```
84128
```
85129
Gson gson = new Gson();
86130
87131
InboundParser parser = new GsonInboundParser(gson) {
88132
89133
@Override
90134
public String getChannelName(JsonElement data) {
91-
return object.getAsJsonObject().get("channel").getAsString();
135+
return data.getAsJsonObject().get("channel").getAsString();
92136
}
93137
};
138+
```
94139

140+
#### Customize Outbound Message Serializer
141+
```
142+
public class GsonOutboundSerializer implements OutboundSerializer {
143+
...
144+
public GsonOutboundSerializer(Gson gson) {
145+
...
146+
}
95147
148+
@Override
149+
public String serialize(String messageType, Map<String, Object> parameterMap) {
150+
...
151+
}
152+
}
153+
```
154+
```
155+
Gson gson = new Gson();
96156
OutboundSerializer serializer = new GsonOutboundSerializer(gson);
97157
```
98158

99-
##### WebSocketClient 인스턴스 생성
159+
### Configuration
160+
#### Use builder class
100161
```
101162
JWebSocket webSocketClientFactory = new JWebSocket.Builder()
102163
.connectionFactory(connectionFactory)
@@ -109,7 +170,7 @@ JWebSocket webSocketClientFactory = new JWebSocket.Builder()
109170
TestClient client = webSocketClientFactory.create(TestClient.class, "ws://localhost/ws");
110171
```
111172

112-
##### Annotation 으로 WebSocketClient 설정
173+
#### Use annotation
113174
```
114175
@WebSocketClient(
115176
url = "wss://echo.websocket.org",
@@ -125,6 +186,15 @@ public interface TestClient {...}
125186
TestClient client = JWebSocket.create(TestClient.class);
126187
```
127188

189+
#### Lazy (default : false)
190+
When this option is enabled, the 'ConnectionFactory' specified by the user is wrapped in 'LazyConnectionFactory'.
191+
'LazyConnection' created by 'LazyConnectionFactory' automatically terminates the connection when there is no 'Observable' subscribing to the connection.
192+
And if the 'sendMessage' method is called, or if there is one or more subscription 'Observable', it automatically creates a connection.
193+
194+
#### Error propagation (default : true)
195+
This option allows you to set whether or not to notify 'Observable' of errors that occur on the connection.
196+
'Observable' in 'RxJava' will automatically terminate the stream when 'onError' is called.
197+
If you want to restore the connection and re-use 'Observable', disable this option.
128198

129-
### 스트림 데이터 플로우 및 이벤트 시점
199+
### Inbound message flow chart and event timing
130200
![DataFlow](./data-flow.png?raw=true "DataFlow")

0 commit comments

Comments
 (0)