简体   繁体   English

如果我重用在 vertx 端点中向外部服务发出请求的自定义客户端,一个请求中的用户异常会阻止另一个用户的异常吗?

[英]If I reuse a custom client that makes requests to an external service in an vertx endpoint, will user exceptions in one request block another user's?

I'm building a data flow pipeline for cached database queries for multiple users with Kafka and Flink etc. and I am confused about when I need to implement multi threading.我正在使用 Kafka 和 Flink 等为多个用户构建缓存数据库查询的数据流管道,我对何时需要实现多线程感到困惑。

I have a built a user service that contains an HTTP server using Vertx.我已经构建了一个用户服务,其中包含使用 Vertx 的 HTTP 服务器。 I have an endpoint that accepts some input from users.我有一个接受用户输入的端点。 One of the endpoints makes a network request to a Kafka service and returns some information from a topic to the user.其中一个端点向 Kafka 服务发出网络请求,并将主题中的一些信息返回给用户。 I created a "kafka client" for this, and in every user request to the endpoint I create a new instance of this kafka client to send the request.我为此创建了一个“kafka 客户端”,并且在每个用户对端点的请求中,我创建了这个 kafka 客户端的一个新实例来发送请求。 Every user's request is totally unrelated, so it doesn't matter whose request gets processed first - there's no race condition to worry about.每个用户的请求都是完全不相关的,所以谁的请求首先被处理并不重要——不用担心竞争条件。

  1. If I create a new instance of this kafka client for every incoming user request, an exception thrown in user 1's request should not block user 2's request right?如果我为每个传入的用户请求创建此 kafka 客户端的新实例,则用户 1 的请求中引发的异常不应阻止用户 2 的请求,对吗? (because I'm already in a separate user thread)? (因为我已经在一个单独的用户线程中)?

  2. Is creating a new instance of a client on every request a good practice?在每个请求上创建一个新的客户端实例是一种好习惯吗? I'm used to creating singletons and reusing them in Node projects (not sure how you even "import" classes in Java).我习惯于创建单例并在 Node 项目中重用它们(不知道你是如何在 Java 中“导入”类的)。

  3. Instead of creating new instances on every request, if I create one singleton client and import it into the endpoint so that it gets reused on every user's request, would an exception thrown in user 1's request then block user 2's request?如果我不是在每个请求上创建新实例,而是创建一个单例客户端并将其导入端点以便在每个用户的请求中重复使用,那么用户 1 的请求中会抛出异常然后阻止用户 2 的请求吗? (Unless I manually added multithreading) or if each user gets their own thread, an exception in user 1's thread would not affect user 2's thread even if they're using the same singleton? (除非我手动添加了多线程)或者如果每个用户都有自己的线程,那么用户 1 的线程中的异常不会影响用户 2 的线程,即使他们使用相同的单例?

In vert.x you typically try to avoid implementing multithreading yourself.在 vert.x 中,您通常会尽量避免自己实现多线程。 You should simply create your handlers and vert.x will call them when they are needed.您应该简单地创建您的处理程序,vert.x 会在需要时调用它们。 You can read more about how this works in vert.x here .你可以在这里阅读更多关于它在 vert.x 中的工作原理。

  1. Thrown exceptions don't block any request, not even the one where they are thrown.抛出的异常不会阻止任何请求,甚至不会阻止它们被抛出的请求。 They will however cause the request to fail, if you forget to handle them .但是,如果您忘记处理它们,它们将导致请求失败。 The exception would not affect the request of the second user at all, because they are isolated from each other.该异常根本不会影响第二个用户的请求,因为它们是相互隔离的。 Note that this also depends on the nature of the exception.请注意,这也取决于异常的性质。 If you share your kafka client and it gets disconnected, then all users will get the same error individually.如果您共享您的 kafka 客户端并且它断开连接,那么所有用户将分别收到相同的错误。

  2. That completely depends on the client that you are creating and you should check out their documentation.这完全取决于您正在创建的客户端,您应该查看他们的文档。 You can also have a look at connection pooling if you're interested in this topic.如果您对此主题感兴趣,还可以查看连接池 You can try creating the client inside of your class, instead of creating a new one for each request.您可以尝试在类中创建客户端,而不是为每个请求创建一个新客户端。 You can also use the vert.x kafka client and create it inside your verticle's start function.您还可以使用vert.x kafka 客户端并在您的 verticle 的start函数中创建它。 This way you should be on the safe side.这样你应该是安全的。

  3. Same as 1.同 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅对用户自己的端点启用请求 - How can I enable request only for user's own endpoint 客户端捕获Web服务用户异常[Java 6.0.17] - Client catching Web Service User Exceptions [Java 6.0.17] 关于如何扩展serv的Vertx处理程序请求的Spring服务的建议 - Advice how to scale Spring service that serv's Vertx handlers requests 如何在不刷新用户会话的情况下向客户端提供请求? - How can I serve requests to a client without refreshing the user's session? 阻止来自URL的用户请求 - Block the user request from URL Vertx 用户授权主体或属性 - Vertx user authorization principal or attributes Spring - 将一个端点的响应连接到另一个端点的请求 - Spring - Connecting a response from one endpoint to a request to another endpoint 我希望将线性布局中的一个(左侧或右侧,取决于用户的选择)替换为自定义的线性布局 - i want one (left or right side depending on user's choice)of the linearlayout to be replaced with a custom Linear layout 我正在制作一个打电话的应用程序,如何保存多个数字,然后给用户选择其中一个? - I am making an app that makes calls, how to save multiple numbers and then give to the user choose one of them? 如何在Vertx Kafka客户端中使用自定义序列化程序? - How to use a custom serializer in Vertx Kafka client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM