Vert.x 3学习笔记---03

本文详细介绍了Vert.x 3中的Event Bus,它是Vert.x应用的通信核心,支持发布/订阅、点对点和请求-响应消息模式。Event Bus提供了简单API,包括注册、注销处理器,发送和发布消息等功能,并可扩展支持自定义对象编码解码。此外,还涵盖了集群化Event Bus的配置和自动清理Verticle中的处理器。
摘要由CSDN通过智能技术生成

The Event Bus

概述

本文介绍event bus。
The event bus is the nervous system of Vert.x.
每一个Vertx实例都只有一个event bus实例,可以使用eventBus方法获取。event bus容许你的应用程序的各个部分(相同或者不同语言编写的,相同或者不同的vertx或者vertx的其他部分)进行通讯。
The event bus allows different parts of your application to communicate with each other irrespective of what language they are written in, and whether they’re in the same Vert.x instance, or in a different Vert.x instance.
它甚至允许客户端JavaScript(浏览器中)去通讯,只要在同一个event bus中。
It can even be bridged to allow client side JavaScript running in a browser to communicate on the same event bus.

The event bus forms a distributed peer-to-peer messaging system spanning multiple server nodes and multiple browsers.

The event bus supports publish/subscribe, point to point, and request-response messaging.

The event bus API is very simple. It basically involves registering handlers, unregistering handlers and sending and publishing messages.

The Theory 理论知识

Addressing

在event bus上,消息被发送到一个地址。
在vertx中,一个地址就是一个字符串。任何字符串都是合法的。例如:europe.news.feed1, acme.games.pacman, sausages, and X。

Handlers

在handler中消息被接收。你在一个地址上面注册一个handler。
不同的handler可以注册在同一个地址上。
一个handler可以注册在不同的地址上。

Publish / subscribe messaging

event bus支持发布/订阅消息。

Point to point and Request-Response messaging

event bus支持点对点和请求/响应传递消息。

Best-effort delivery 尽力投递

vertx内置的message传递的类型为原始/简单的类型,字符串,buffer。最佳实践类型格式为json。
当然我们并不强制你必须使用json。event bus也是可以扩展的,可以支持任意的对象,只要你为这些对象实现了codec

The Event Bus API

Getting the event bus

EventBus eb = vertx.eventBus();

There is a single instance of the event bus per Vert.x instance.
每一个vertx实例都有一个单实例的event bus对象。

Registering Handlers

EventBus eb = vertx.eventBus();
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值