如何在顶点路由器处理程序中使用Mutiny单元?



返回一个包含"hello">

的HTTP响应体
router.get("/").respond(rc -> 
Uni.createFrom().item("hello")
);

router
.get("/hello")
.handler(context ->
Uni.createFrom().item("hello")
.subscribe()
.with(item -> context.end(item))
);

我错过了什么?

RoutingContext#end(java.lang.String)返回一个Uni,它是惰性的。如果你不订阅,什么也不会发生。

如果你不关心结果,使用RoutingContext#endAndForget(java.lang.String)代替:

router
.get("/hello")
.handler(context ->
Uni.createFrom().item("hello")
.subscribe()
.with(item -> context.endAndForget(item))
);

最新更新