-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
956fabf
commit 278d653
Showing
7 changed files
with
165 additions
and
50 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
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
88 changes: 88 additions & 0 deletions
88
src/main/java/rs/iggy/clients/blocking/tcp/ConsumerGroupsTcpClient.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,88 @@ | ||
package rs.iggy.clients.blocking.tcp; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import rs.iggy.clients.blocking.ConsumerGroupsClient; | ||
import rs.iggy.consumergroup.ConsumerGroup; | ||
import rs.iggy.consumergroup.ConsumerGroupDetails; | ||
import rs.iggy.identifier.ConsumerGroupId; | ||
import rs.iggy.identifier.StreamId; | ||
import rs.iggy.identifier.TopicId; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import static rs.iggy.clients.blocking.tcp.BytesDeserializer.readConsumerGroup; | ||
import static rs.iggy.clients.blocking.tcp.BytesDeserializer.readConsumerGroupDetails; | ||
import static rs.iggy.clients.blocking.tcp.BytesSerializer.nameToBytes; | ||
import static rs.iggy.clients.blocking.tcp.BytesSerializer.toBytes; | ||
|
||
class ConsumerGroupsTcpClient implements ConsumerGroupsClient { | ||
|
||
private static final int GET_CONSUMER_GROUP_CODE = 600; | ||
private static final int GET_CONSUMER_GROUPS_CODE = 601; | ||
private static final int CREATE_CONSUMER_GROUP_CODE = 602; | ||
private static final int DELETE_CONSUMER_GROUP_CODE = 603; | ||
private static final int JOIN_CONSUMER_GROUP_CODE = 604; | ||
private static final int LEAVE_CONSUMER_GROUP_CODE = 605; | ||
|
||
private final TcpConnectionHandler connection; | ||
|
||
public ConsumerGroupsTcpClient(TcpConnectionHandler connection) { | ||
this.connection = connection; | ||
} | ||
|
||
@Override | ||
public ConsumerGroupDetails getConsumerGroup(StreamId streamId, TopicId topicId, ConsumerGroupId groupId) { | ||
var payload = toBytes(streamId); | ||
payload.writeBytes(toBytes(topicId)); | ||
payload.writeBytes(toBytes(groupId)); | ||
var response = connection.send(GET_CONSUMER_GROUP_CODE, payload); | ||
return readConsumerGroupDetails(response); | ||
} | ||
|
||
@Override | ||
public List<ConsumerGroup> getConsumerGroups(StreamId streamId, TopicId topicId) { | ||
var payload = toBytes(streamId); | ||
payload.writeBytes(toBytes(topicId)); | ||
var response = connection.send(GET_CONSUMER_GROUPS_CODE, payload); | ||
List<ConsumerGroup> groups = new ArrayList<>(); | ||
while (response.isReadable()) { | ||
groups.add(readConsumerGroup(response)); | ||
} | ||
return groups; | ||
} | ||
|
||
@Override | ||
public ConsumerGroupDetails createConsumerGroup(StreamId streamId, TopicId topicId, Optional<Long> groupId, String name) { | ||
var streamIdBytes = toBytes(streamId); | ||
var topicIdBytes = toBytes(topicId); | ||
var payload = Unpooled.buffer(5 + streamIdBytes.readableBytes() + topicIdBytes.readableBytes() + name.length()); | ||
|
||
payload.writeBytes(streamIdBytes); | ||
payload.writeBytes(topicIdBytes); | ||
payload.writeIntLE(groupId.orElse(0L).intValue()); | ||
payload.writeBytes(nameToBytes(name)); | ||
|
||
ByteBuf response = connection.send(CREATE_CONSUMER_GROUP_CODE, payload); | ||
return readConsumerGroupDetails(response); | ||
} | ||
|
||
@Override | ||
public void deleteConsumerGroup(StreamId streamId, TopicId topicId, ConsumerGroupId groupId) { | ||
var payload = toBytes(streamId); | ||
payload.writeBytes(toBytes(topicId)); | ||
payload.writeBytes(toBytes(groupId)); | ||
connection.send(DELETE_CONSUMER_GROUP_CODE, payload); | ||
} | ||
|
||
@Override | ||
public void joinConsumerGroup(StreamId streamId, TopicId topicId, ConsumerGroupId groupId) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void leaveConsumerGroup(StreamId streamId, TopicId topicId, ConsumerGroupId groupId) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
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
13 changes: 13 additions & 0 deletions
13
src/test/java/rs/iggy/clients/blocking/tcp/ConsumerGroupsTcpClientTest.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,13 @@ | ||
package rs.iggy.clients.blocking.tcp; | ||
|
||
import rs.iggy.clients.blocking.ConsumerGroupsClientBaseTest; | ||
import rs.iggy.clients.blocking.IggyClient; | ||
|
||
class ConsumerGroupsTcpClientTest extends ConsumerGroupsClientBaseTest { | ||
|
||
@Override | ||
protected IggyClient getClient() { | ||
return TcpClientFactory.create(iggyServer); | ||
} | ||
|
||
} |