vert.x

Vert.x系列(一)--Vert.x介绍

不想你离开。 提交于 2021-02-06 02:58:18
1.Vert.x 介绍 Vert.x(官网:https://vertx.io/ )基于JVM、轻量级、高性能Java框架。 功能强大,第三方库依赖少的。 它只依赖Netty4以及Jackson。 分布式情况下还要依赖HazelCast这个分布式框架。 包含了一个企业级应用程序所需的所有要求。 2.Vert.x 组件概念 1.Vertx: 框架核心,所有程序共享一个vertx实例: 分为2种:单机vertx() / 分布式:clusteredVertx()。 是大部分功能的基础。 如果要举例的的话,比较像Spring的 ApplicationContext。 代码: Vertx vertx = Vertx.vertx(); 2.Verticle 业务处理单元,所有的自定义类需要继承Verticle或AbstractVerticle。 分为3种: Standard Verticles 这是最常见和通用的类型-他们总是使用一个 event loop thread(事件循环线程) 执行。 Worker Verticles 用于执行阻塞任务 Multi-threaded worker Verticles 使用来自 worker pool(工作者线程池) 中的线程运行。一个实例可以被多个线程同时执行。(高级特性,不推荐使用) 代码: public class MyVerticle

Sub router cannot be mounted on an exact path

扶醉桌前 提交于 2021-01-29 18:55:53
问题 I would like to do nested routes in vert.x and I have tried the following: class MainVerticle : AbstractVerticle() { private fun apiResource(r: Router): Unit { r.route("/api") .subRouter(GenderResource(vertx).create()) } private fun rootResource(r: Router): Unit { r.route("/").handler { val res = it.response() res.putHeader("content-type", "text/plain"); // Write to the response and end it res.end("I am healthy"); } } override fun start(startPromise: Promise<Void>) { val server = vertx

I am mocking the method but in the test when i called the method, debugger going inside the method and expecting something i am not sure why

廉价感情. 提交于 2021-01-29 17:20:52
问题 Here I am mocking it and expecting nothing from the method, but when I send the request body through eventbus request was going inside the method, which I am not expecting. Can anyone help me with this issue? I didn't mocked any JDBC client and in the config file too I am giving empty credentials, since I am mocking it. public class verticle extends AbstractVertcile { private void jdbcCall(JsonArray data, Future<JsonArray> promise) { String first_name = data.getValue(first_name); String last

Vertx EventBus Reply a 'Specific' Message

落爺英雄遲暮 提交于 2021-01-29 07:25:24
问题 We have a case as below: The concern is that, the Coordinator sends out a message from a method context and gets the reponse from another: private void forwardToVWClient(Message msg) { vertx.eventBus().send(RESTClient.ADDRESS, msg.body(), deliveryOptions, res -> { if (res.succeeded()) { log.info("forwardToVWClient. VW got result : success."); // do not reply ok until we get an OK from the Listener verticle } else { log.error("forwardToVWClient VW got result : failure."); msg.fail(500, res

Concept of vert.x concerning a webserver?

廉价感情. 提交于 2021-01-28 23:51:45
问题 I don't quite get how vert.x is applied for a webserver. The concept I know for webserver is the thread-based one. You start your webserver, which then is running. Then for every client that connects, you get a socket, which is then passed to its own thread handler. The thread handler then processes the tasks for this specific socket. So it is clearly defined which thread is doing the work for which socket. However for every socket you need a new thread, which is expensive in the long run for

Concept of vert.x concerning a webserver?

﹥>﹥吖頭↗ 提交于 2021-01-28 23:37:02
问题 I don't quite get how vert.x is applied for a webserver. The concept I know for webserver is the thread-based one. You start your webserver, which then is running. Then for every client that connects, you get a socket, which is then passed to its own thread handler. The thread handler then processes the tasks for this specific socket. So it is clearly defined which thread is doing the work for which socket. However for every socket you need a new thread, which is expensive in the long run for

Handling hundreds of routes in Vert.x best practices

我是研究僧i 提交于 2021-01-28 08:43:32
问题 Please have a look at the piece of code below. Now suppose i'll have hundreds of entity like "person". How would you code such a thing to get it clean, concise, efficient, well structured ? Tx class HttpEntryPoint : CoroutineVerticle() { private suspend fun person(r: RoutingContext) { val res = vertx.eventBus().requestAwait<String>("/person/:id", "1").body() r.response().end(res) } override suspend fun start() { val router = Router.router(vertx) router.get("/person/:id").coroutineHandler {

how to set system property in spring boot application

余生长醉 提交于 2021-01-28 04:56:04
问题 I have a requirement to set system property in spring boot application. I don't want to set it from command line. My concern is what is the best practice to do it. Either from constructor Or inside main method. Below is sample for setting it from constructor @SpringBootApplication class Sample{ @Autowired protected TempInfoDao tempInfoDao; public Sample{ //Setting System property inside constructor System.setProperty("vertx.hazelcast.config","./config/cluster.xml"); } /** * @param args */

Vert.x Test halts with TimeoutException: The test execution timed out

拈花ヽ惹草 提交于 2021-01-07 04:13:44
问题 I'm using Vert.x 3.5.3 . I have this (simple) Verticle: class DialPadVerticle : AbstractVerticle() { private companion object : KLogging() override fun start(future: Future<Void>) { vertx.eventBus().consumer(Address.DIALPAD_COMBINATIONS) { message: Message<Int> -> val input = message.body() logger.info { "Received: $input" } message.reply(JsonObject().put("result", DialPad().combinations(input))) } future.complete() } override fun stop(future: Future<Void>) { logger.debug { "Stopping ${this

Vert.x Test halts with TimeoutException: The test execution timed out

给你一囗甜甜゛ 提交于 2021-01-07 04:10:01
问题 I'm using Vert.x 3.5.3 . I have this (simple) Verticle: class DialPadVerticle : AbstractVerticle() { private companion object : KLogging() override fun start(future: Future<Void>) { vertx.eventBus().consumer(Address.DIALPAD_COMBINATIONS) { message: Message<Int> -> val input = message.body() logger.info { "Received: $input" } message.reply(JsonObject().put("result", DialPad().combinations(input))) } future.complete() } override fun stop(future: Future<Void>) { logger.debug { "Stopping ${this