-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Pub & Sub = <3 #1662
Java: Pub & Sub = <3 #1662
Conversation
* Add client configuartion for subscribing to channels. Signed-off-by: Yury-Fridlyand <[email protected]> * CLIPPY I HATE YOU Signed-off-by: Yury-Fridlyand <[email protected]> * Get and store callback. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Rework configuration and add docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Config rework. Signed-off-by: Yury-Fridlyand <[email protected]> * docs Signed-off-by: Yury-Fridlyand <[email protected]> * More TODOs for the god of TODOs. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
* Add `PUBLISH` and `SPUBLISH` commands. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix the test. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
* Add client configuartion for subscribing to channels. Signed-off-by: Yury-Fridlyand <[email protected]> * CLIPPY I HATE YOU Signed-off-by: Yury-Fridlyand <[email protected]> * Get and store callback. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Rework configuration and add docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Config rework. Signed-off-by: Yury-Fridlyand <[email protected]> * docs Signed-off-by: Yury-Fridlyand <[email protected]> * Receive pushes (subscibed messages). Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * I HATE YOU SPOTLESS Signed-off-by: Yury-Fridlyand <[email protected]> * Rename a class. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
…bsub Signed-off-by: Yury-Fridlyand <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed and posted comments from the beginning to java/client/src/main/java/glide/api/models/configuration/BaseClientConfiguration.java
+ " callback."); | ||
} | ||
// TODO | ||
throw new NotImplementedException("oh no"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not implemented and won't be in the foreseeable future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a more meaningful error message here, along with the TODO link to documentation (perhaps explaining the limitation?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, WIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 5a11ff4
? new BaseCommandResponseResolver(RedisValueResolver::valueFromPointer).apply(response) | ||
: new BaseCommandResponseResolver(RedisValueResolver::valueFromPointerBinary) | ||
.apply(response); | ||
encodingUtf8 ? responseResolver.apply(response) : binaryResponseResolver.apply(response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how its applies to pubsub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageHandler
uses responseResolver
to get the message from received push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this answer your question @ikolomi ?
BaseClientConfiguration config, | ||
BiFunction<ConnectionManager, CommandManager, T> constructor) { | ||
protected static <T extends BaseClient> CompletableFuture<T> CreateClient( | ||
@NonNull BaseClientConfiguration config, Supplier<T> constructor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how it is related to the pubsub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to rework it since BaseClient
got more private fields to store.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this answer your question @ikolomi ?
} | ||
return new MessageHandler( | ||
config.getSubscriptionConfiguration().getCallback(), | ||
config.getSubscriptionConfiguration().getContext(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a validation that context cannot be set w/o the callback and the subscriptions cannot be used with resp2, do we have it here?
https://github.com/aws/glide-for-redis/blob/e2a804c2f1d6355a797a60f28e95c2d16826a856/python/python/glide/config.py#L451
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java client does not support RESP2 yet. I put a todo.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ikolomi , does this cover your concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this takes in both callback and context in one method, the caller could supply null to either of these. I've added an explict check for this in #1773.
* @param message The message to publish. | ||
* @return Command response - The number of clients that received the message. | ||
*/ | ||
public ClusterTransaction spublish(@NonNull String channel, @NonNull String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very sharded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done in #1773
java/client/src/main/java/glide/api/models/configuration/BackoffStrategy.java
Show resolved
Hide resolved
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
…bsub Signed-off-by: Yury-Fridlyand <[email protected]>
* Add some tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Test fixes. Signed-off-by: Yury-Fridlyand <[email protected]> * Add more tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Experiment Signed-off-by: Yury-Fridlyand <[email protected]> * Add more tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * I HATE YOU SPOTLESS Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Uncomment test timeout. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
…bsub Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
java/client/src/main/java/glide/api/models/BaseTransaction.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/configuration/BaseSubscriptionConfiguration.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/configuration/BaseSubscriptionConfiguration.java
Show resolved
Hide resolved
@@ -45,7 +46,12 @@ public void init() { | |||
connectionManager = mock(ConnectionManager.class); | |||
threadPoolResource = mock(ThreadPoolResource.class); | |||
|
|||
mockedClient.when(() -> buildChannelHandler(any())).thenReturn(channelHandler); | |||
RedisClient client = new RedisClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This client needs to close() right? Need a try-with-resources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all instances are mocks here, so I think we can omit that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RedisClient itself isn't a mock. Adding try-with-resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, the client is now mocked.
java/client/src/test/java/glide/managers/CommandManagerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Yury-Fridlyand <[email protected]>
…bsub Signed-off-by: Yury-Fridlyand <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signing off on the Rust changes with some minor comments.
// Create a java `Map<String, Object>` with two keys: | ||
// - "kind" which corresponds to the push type, stored as a `String` | ||
// - "values" which corresponds to the array of values received, stored as `Object[]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we only have 2 keys, why not just return an array of 2 elements? Not a big deal, but I'm curious why we went with a Map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, but I'm following python client.
Signed-off-by: Yury-Fridlyand <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The feature is not done until all the comments are resolved and explicitly approved by myself.
- Do reach out actively to me to in case of any questions arise.
} | ||
return new MessageHandler( | ||
config.getSubscriptionConfiguration().getCallback(), | ||
config.getSubscriptionConfiguration().getContext(), |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
"The operation will never complete since messages will be passed to the configured" | ||
+ " callback."); | ||
} | ||
throw new NotImplementedException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be implemented to be on a par with python implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #1770
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this cover the ask @ikolomi ?
* @param message The message to publish. | ||
* @return Command response - The number of clients that received the message. | ||
*/ | ||
public ClusterTransaction spublish(@NonNull String channel, @NonNull String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- implement getPubSubMessage() flavors
- implement the missing tests per reference ( https://github.com/aws/glide-for-redis/blob/main/python/python/tests/test_pubsub.py) :
test_pubsub_exact_happy_path_coexistence
test_pubsub_exact_happy_path_many_channels_co_existence
test_sharded_pubsub_co_existence
test_pubsub_pattern_co_existence
test_pubsub_pattern_many_channels
test_pubsub_combined_exact_and_pattern_one_client
test_pubsub_combined_exact_and_pattern_multiple_clients
test_pubsub_combined_exact_pattern_and_sharded_multi_client
test_pubsub_combined_different_channels_with_same_name
test_pubsub_two_publishing_clients_same_name
test_pubsub_exact_max_size_message
test_pubsub_sharded_max_size_message
test_pubsub_exact_max_size_message_callback
test_pubsub_sharded_max_size_message_callback
test_pubsub_resp2_raise_an_error
test_pubsub_context_with_no_callback_raise_error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- All "coexistence" tests depend on
getPubSubMessage
and wait for it. - All "max_size_message" tests disabled on python side due to a bug and there is no reason to implement them now until bug fixed.
- RESP2 is not supported by java client - no test there.
- All rest are implemented.
public CompletableFuture<String> publish(@NonNull String channel, @NonNull String message) { | ||
return commandManager.submitNewCommand( | ||
Publish, | ||
new String[] {channel, message}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we still using Strings?
@@ -780,6 +782,18 @@ public CompletableFuture<String> randomKey() { | |||
RandomKey, new String[0], this::handleStringOrNullResponse); | |||
} | |||
|
|||
@Override | |||
public CompletableFuture<String> spublish(@NonNull String channel, @NonNull String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a GlideString
variant for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eifrah-aws , I've removed spublish and made two overloads of publish(). They both use ArgType now. Please see: #1773.
* assert response.equals("OK"); | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> spublish(String channel, String message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlideString
variant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1773
* assert response.equals("OK"); | ||
* }</pre> | ||
*/ | ||
CompletableFuture<String> publish(String channel, String message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlideString
variant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1773
* Java: Add client configuration for subscribing to channels. (#381) * Add client configuartion for subscribing to channels. Signed-off-by: Yury-Fridlyand <[email protected]> * CLIPPY I HATE YOU Signed-off-by: Yury-Fridlyand <[email protected]> * Get and store callback. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Rework configuration and add docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Config rework. Signed-off-by: Yury-Fridlyand <[email protected]> * docs Signed-off-by: Yury-Fridlyand <[email protected]> * More TODOs for the god of TODOs. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> * Add `PUBLISH` and `SPUBLISH` commands. (#391) * Add `PUBLISH` and `SPUBLISH` commands. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix the test. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> * Java client: receive pubsub messages (#385) * Add client configuartion for subscribing to channels. Signed-off-by: Yury-Fridlyand <[email protected]> * CLIPPY I HATE YOU Signed-off-by: Yury-Fridlyand <[email protected]> * Get and store callback. Signed-off-by: Yury-Fridlyand <[email protected]> * Fix tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Rework configuration and add docs. Signed-off-by: Yury-Fridlyand <[email protected]> * Config rework. Signed-off-by: Yury-Fridlyand <[email protected]> * docs Signed-off-by: Yury-Fridlyand <[email protected]> * Receive pushes (subscibed messages). Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * I HATE YOU SPOTLESS Signed-off-by: Yury-Fridlyand <[email protected]> * Rename a class. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Java: add IT for pubsub (#400) * Add some tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Test fixes. Signed-off-by: Yury-Fridlyand <[email protected]> * Add more tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Experiment Signed-off-by: Yury-Fridlyand <[email protected]> * Add more tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * I HATE YOU SPOTLESS Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Uncomment test timeout. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> * Update function signature. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR comments. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
Issue #, if available:
PubSub support for Java client
Ref: #1602, #1616, #1650, #1643 and #1741
Description of changes:
Configuration with callback:
To send messages use
Configuration without callback:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.