Skip to content
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

Add asynchronous MessageHandler interface #934

Open
matthewadams opened this issue Jun 28, 2023 · 4 comments
Open

Add asynchronous MessageHandler interface #934

matthewadams opened this issue Jun 28, 2023 · 4 comments
Labels
proposal Enhancement idea or proposal

Comments

@matthewadams
Copy link

Feature Request

The current MessageHandler interface has a synchronous method. Please provide an asynchronous version of the same interface.

Use Case:

Not sure, but hoping that providing this would allow more messages to be handled at a given time.

Proposed Change:

public interface AsyncMessageHandler {
    CompletableFuture<Void> onMessage(Message msg);
}

along with concomitant changes, like adding a method to Connection like AsyncDispatcher createAsyncDispatcher(AsyncMessageHandler handler).

Who Benefits From The Change(s)?

Those writing MessageHandlers that invoke asynchronous methods, specifically, Kotlin suspend functions, as well as future use by Java fibers (Project Loom).

Alternative Approaches

?

@scottf
Copy link
Contributor

scottf commented Jun 28, 2023

I'm happy to discuss this with the clients development teams, but you can certainly accomplish this yourself, by having your synchronous message handler distribute the messages asynchronously.

@bruth bruth added proposal Enhancement idea or proposal and removed 🎉 enhancement labels Aug 18, 2023
@liangyuanpeng
Copy link

Vertx for nats may help : https://github.com/nats-io/nats-java-vertx-client

@scottf
Copy link
Contributor

scottf commented Sep 15, 2023

Vertx for nats may help : https://github.com/nats-io/nats-java-vertx-client

It won't. That vertx client is a wrapper around the existing client. It's on the roadmap to replace the connection layer in the current client with actual vertx

@matthewadams
Copy link
Author

As long as I can use the Java client from Kotlin with suspend funs, I'm ok, but I'd rather see y'all either rewrite the Java client in Kotlin, or provide a native Kotlin client.

Is it on the roadmap to support Java fibers/virtual threads/Project Loom?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

4 participants