-
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.
initial binary client based on Netty
- Loading branch information
1 parent
8250803
commit a953e07
Showing
18 changed files
with
316 additions
and
177 deletions.
There are no files selected for viewing
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
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
10 changes: 0 additions & 10 deletions
10
src/main/java/com/github/nginate/kafka/core/ConnectionEventListener.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/com/github/nginate/kafka/core/KafkaBrokerClient.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,40 @@ | ||
package com.github.nginate.kafka.core; | ||
|
||
import com.github.nginate.kafka.exceptions.CommunicationException; | ||
import com.github.nginate.kafka.network.client.BinaryTcpClient; | ||
import com.github.nginate.kafka.network.client.BinaryTcpClientConfig; | ||
import com.github.nginate.kafka.protocol.messages.Request; | ||
import com.github.nginate.kafka.protocol.messages.Response; | ||
import lombok.Builder; | ||
|
||
import java.io.Closeable; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Builder(toBuilder = true) | ||
public class KafkaBrokerClient implements Closeable { | ||
private final BinaryTcpClient binaryTcpClient; | ||
|
||
public KafkaBrokerClient(String host, int port) { | ||
BinaryTcpClientConfig config = BinaryTcpClientConfig.custom().host(host).port(port).build(); | ||
binaryTcpClient = new BinaryTcpClient(config); | ||
} | ||
|
||
public void connect() { | ||
binaryTcpClient.connect(); | ||
} | ||
|
||
public void send(Request request) { | ||
Response response = (Response) binaryTcpClient.request(request).join(); | ||
// TODO: check ack from broker | ||
} | ||
|
||
public <T extends Response> CompletableFuture<T> sendAndReceive(Request request, Class<T> responseClass) | ||
throws CommunicationException { | ||
return binaryTcpClient.request(request).thenApply(responseClass::cast); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
binaryTcpClient.close(); | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
src/main/java/com/github/nginate/kafka/core/KafkaConnection.java
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
src/main/java/com/github/nginate/kafka/core/KafkaConnectionPool.java
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/main/java/com/github/nginate/kafka/network/AnswerableMessage.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,5 @@ | ||
package com.github.nginate.kafka.network; | ||
|
||
public interface AnswerableMessage<T> { | ||
T getCorrelationId(); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/github/nginate/kafka/network/BinaryMessageDecoder.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,18 @@ | ||
package com.github.nginate.kafka.network; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.ReplayingDecoder; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public class BinaryMessageDecoder extends ReplayingDecoder<Void> { | ||
private final BinaryMessageSerializer serializer; | ||
|
||
@Override | ||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { | ||
out.add(serializer.deserialize(in)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/github/nginate/kafka/network/BinaryMessageEncoder.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,17 @@ | ||
package com.github.nginate.kafka.network; | ||
|
||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.MessageToByteEncoder; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class BinaryMessageEncoder extends MessageToByteEncoder<AnswerableMessage> { | ||
private final BinaryMessageSerializer serializer; | ||
|
||
@Override | ||
protected void encode(ChannelHandlerContext ctx, AnswerableMessage msg, ByteBuf out) throws Exception { | ||
serializer.serialize(out, msg); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/github/nginate/kafka/network/BinaryMessageSerializer.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,10 @@ | ||
package com.github.nginate.kafka.network; | ||
|
||
import com.github.nginate.kafka.exceptions.SerializationException; | ||
import io.netty.buffer.ByteBuf; | ||
|
||
public interface BinaryMessageSerializer { | ||
void serialize(ByteBuf buf, Object message) throws SerializationException; | ||
|
||
Object deserialize(ByteBuf buf) throws SerializationException; | ||
} |
Oops, something went wrong.