forked from Linyuzai/concept
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
164 additions
and
45 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...m/github/linyuzai/connection/loadbalance/core/subscribe/ProtocolConnectionSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.subscribe; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
|
||
public abstract class ProtocolConnectionSubscriber<T extends Connection> extends ServerInstanceConnectionSubscriber<T> { | ||
|
||
public abstract void setProtocol(String protocol); | ||
} |
23 changes: 23 additions & 0 deletions
23
...b/linyuzai/connection/loadbalance/core/subscribe/ProtocolConnectionSubscriberFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.linyuzai.connection.loadbalance.core.subscribe; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.Connection; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class ProtocolConnectionSubscriberFactory<T extends Connection> extends AbstractConnectionSubscriberFactory { | ||
|
||
private String protocol; | ||
|
||
@Override | ||
public ConnectionSubscriber create(String scope) { | ||
ProtocolConnectionSubscriber<T> subscriber = doCreate(scope); | ||
if (protocol != null && !protocol.isEmpty()) { | ||
subscriber.setProtocol(protocol); | ||
} | ||
return subscriber; | ||
} | ||
|
||
public abstract ProtocolConnectionSubscriber<T> doCreate(String scope); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../java/com/github/linyuzai/connection/loadbalance/sse/concept/SseConnectionSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.linyuzai.connection.loadbalance.sse.concept; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.subscribe.ProtocolConnectionSubscriber; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* SSE 连接订阅者。 | ||
* <p> | ||
* SSE connection subscriber. | ||
*/ | ||
@Getter | ||
@Setter | ||
public abstract class SseConnectionSubscriber<T extends SseConnection> | ||
extends ProtocolConnectionSubscriber<T> { | ||
|
||
private String protocol = "http"; | ||
|
||
@Override | ||
public String getEndpoint() { | ||
return SseLoadBalanceConcept.SUBSCRIBER_ENDPOINT; | ||
} | ||
|
||
public abstract String getType(); | ||
} |
16 changes: 16 additions & 0 deletions
16
...om/github/linyuzai/connection/loadbalance/sse/concept/SseConnectionSubscriberFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.github.linyuzai.connection.loadbalance.sse.concept; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.subscribe.ProtocolConnectionSubscriberFactory; | ||
|
||
/** | ||
* SSE 连接订阅者工厂抽象类。 | ||
* <p> | ||
* Abstract class of SSE connection subscriber factory. | ||
*/ | ||
public abstract class SseConnectionSubscriberFactory<T extends SseConnection> | ||
extends ProtocolConnectionSubscriberFactory<T> { | ||
|
||
public SseConnectionSubscriberFactory() { | ||
addScopes(SseScoped.NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ava/com/github/linyuzai/connection/loadbalance/sse/reactive/ReactiveSseClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.linyuzai.connection.loadbalance.sse.reactive; | ||
|
||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
public interface ReactiveSseClientFactory { | ||
|
||
WebClient create(); | ||
} |
36 changes: 36 additions & 0 deletions
36
.../github/linyuzai/connection/loadbalance/sse/reactive/ReactiveSseConnectionSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.linyuzai.connection.loadbalance.sse.reactive; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.concept.ConnectionLoadBalanceConcept; | ||
import com.github.linyuzai.connection.loadbalance.sse.concept.SseConnectionSubscriber; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import java.net.URI; | ||
import java.util.function.Consumer; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class ReactiveSseConnectionSubscriber extends SseConnectionSubscriber<ReactiveSseConnection> { | ||
|
||
private final ReactiveSseClientFactory sseClientFactory; | ||
|
||
@Override | ||
public void doSubscribe(URI uri, ConnectionLoadBalanceConcept concept, Consumer<ReactiveSseConnection> onSuccess, Consumer<Throwable> onError, Runnable onComplete) { | ||
WebClient webClient = sseClientFactory.create(); | ||
webClient.get() | ||
.uri(uri).retrieve() | ||
.bodyToFlux(String.class) | ||
.subscribe(new Consumer<String>() { | ||
@Override | ||
public void accept(String s) { | ||
System.out.println(s); | ||
} | ||
}, onError, onComplete); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "reactive"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../linyuzai/connection/loadbalance/sse/reactive/ReactiveSseConnectionSubscriberFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.linyuzai.connection.loadbalance.sse.reactive; | ||
|
||
import com.github.linyuzai.connection.loadbalance.sse.concept.SseConnectionSubscriber; | ||
import com.github.linyuzai.connection.loadbalance.sse.concept.SseConnectionSubscriberFactory; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* Reactive SSE 连接订阅器工厂。 | ||
* <p> | ||
* Reactive SSE connection subscriber factory. | ||
*/ | ||
@Getter | ||
@Setter | ||
public class ReactiveSseConnectionSubscriberFactory extends SseConnectionSubscriberFactory<ReactiveSseConnection> { | ||
|
||
private ReactiveSseClientFactory sseClientFactory; | ||
|
||
@Override | ||
public SseConnectionSubscriber<ReactiveSseConnection> doCreate(String scope) { | ||
return new ReactiveSseConnectionSubscriber(sseClientFactory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 2 additions & 21 deletions
23
...nyuzai/connection/loadbalance/websocket/concept/WebSocketConnectionSubscriberFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,16 @@ | ||
package com.github.linyuzai.connection.loadbalance.websocket.concept; | ||
|
||
import com.github.linyuzai.connection.loadbalance.core.subscribe.AbstractConnectionSubscriberFactory; | ||
import com.github.linyuzai.connection.loadbalance.core.subscribe.ConnectionSubscriber; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.util.StringUtils; | ||
import com.github.linyuzai.connection.loadbalance.core.subscribe.ProtocolConnectionSubscriberFactory; | ||
|
||
/** | ||
* ws 连接订阅者工厂抽象类。 | ||
* <p> | ||
* Abstract class of ws connection subscriber factory. | ||
*/ | ||
@Getter | ||
@Setter | ||
public abstract class WebSocketConnectionSubscriberFactory<T extends WebSocketConnection> | ||
extends AbstractConnectionSubscriberFactory { | ||
|
||
private String protocol; | ||
extends ProtocolConnectionSubscriberFactory<T> { | ||
|
||
public WebSocketConnectionSubscriberFactory() { | ||
addScopes(WebSocketScoped.NAME); | ||
} | ||
|
||
@Override | ||
public ConnectionSubscriber create(String scope) { | ||
WebSocketConnectionSubscriber<T> subscriber = doCreate(scope); | ||
if (StringUtils.hasText(protocol)) { | ||
subscriber.setProtocol(protocol); | ||
} | ||
return subscriber; | ||
} | ||
|
||
public abstract WebSocketConnectionSubscriber<T> doCreate(String scope); | ||
} |