Skip to content

Java client: receive pubsub messages#385

Merged
Yury-Fridlyand merged 12 commits intojava/integ_yuryf_pubsubfrom
java/integ_yuryf_pubsub_receive
Jun 26, 2024
Merged

Java client: receive pubsub messages#385
Yury-Fridlyand merged 12 commits intojava/integ_yuryf_pubsubfrom
java/integ_yuryf_pubsub_receive

Conversation

@Yury-Fridlyand
Copy link
Copy Markdown

@Yury-Fridlyand Yury-Fridlyand commented Jun 21, 2024

Based on #381

Configuration with callback:

    @Test
    @SneakyThrows
    public void basic_client() {
        BiConsumer<Message, Object> callback =
            (msg, context) -> System.out.printf("Received %s, context %s\n", msg, context);

        var regularClient =
                RedisClient.CreateClient(
                                RedisClientConfiguration.builder()
                                        .address(NodeAddress.builder().port(6379).build())
                                        .requestTimeout(3000)
                                        .subscriptionConfiguration(
                                                StandaloneSubscriptionConfiguration.builder()
                                                        .subscription(EXACT, "ch1")
                                                        .subscription(PATTERN, "chat*")
                                                        .callback(callback)
                                                        .build())
                                        .build())
                        .get();

        Thread.sleep(100500);
    }

To send messages use redis-cli: publish ch1 $message

Configuration without callback:

    @Test
    @SneakyThrows
    public void basic_client() {
        var regularClient =
                RedisClient.CreateClient(
                                RedisClientConfiguration.builder()
                                        .address(NodeAddress.builder().port(6379).build())
                                        .requestTimeout(3000)
                                        .subscriptionConfiguration(
                                                StandaloneSubscriptionConfiguration.builder()
                                                        .subscription(EXACT, "ch1")
                                                        .subscription(PATTERN, "chat*")
                                                        .build())
                                        .build())
                        .get();

        Thread.sleep(100500);

        Message msg = null;
        while ((msg = regularClient.tryGetPubSubMessage()) != null) {
            System.out.printf("Received from queue %s\n", msg);
        }
    }

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
/// Recursively calls to [`redis_value_to_java`] for every element.
///
/// Returns an arbitrary java `Object[]`.
fn array_to_java_array<'local>(env: &mut JNIEnv<'local>, values: Vec<Value>) -> JObject<'local> {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from Value::Array handling from above

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand force-pushed the java/integ_yuryf_pubsub_receive branch from df87657 to 30005f8 Compare June 25, 2024 03:31
@Yury-Fridlyand Yury-Fridlyand marked this pull request as ready for review June 25, 2024 03:39
* with a callback.
* @return A message if any or <code>null</code> if there are no unread messages.
*/
public Message tryGetPubSubMessage() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "try"? what is the purpose of this method vs getPubSubMessage?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed python client namings: https://github.com/aws/glide-for-redis/pull/1616/files#diff-f0f69819afe466c0f3e8afd4ea2fd31ca4f451373fa8ed1351f48473a1c39633R5042

async def get_pubsub_message(self) -> PubSubMsg:
def try_get_pubsub_message(self) -> Optional[PubSubMsg]:

public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
// TODO: log thru logger
System.out.printf("=== exceptionCaught %s %s %n", ctx, cause);
cause.printStackTrace();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to log it through logger too.

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
…va/integ_yuryf_pubsub_receive

Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand merged commit e8df28f into java/integ_yuryf_pubsub Jun 26, 2024
@Yury-Fridlyand Yury-Fridlyand deleted the java/integ_yuryf_pubsub_receive branch June 26, 2024 06:30
jamesx-improving pushed a commit that referenced this pull request Jul 1, 2024
* 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]>
cyip10 pushed a commit that referenced this pull request Jul 16, 2024
* 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]>
Yury-Fridlyand added a commit that referenced this pull request Jun 6, 2025
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants