vert.x实践二——基于EventBus的交互demo

本文介绍了如何使用Vert.x框架,通过EventBus进行内部服务交互,并结合HTTP对外提供服务。详细展示了两个Vertx服务的启动类和Verticle,以及HTTP请求和EventBus的请求应答模式,最终实现特定的目录结构和效果。
摘要由CSDN通过智能技术生成

1.代码展示

第一个vertx服务启动类

package org.example;

import com.hazelcast.config.Config;
import com.hazelcast.config.FileSystemXmlConfig;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.EventBusOptions;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author: Administrator
 * @Description:
 * @Date: 2020/7/16 10:42
 * @Version: 1.0
 */
public class AppCluster {
   

    public static void main(String[] args) throws  UnknownHostException {
   
        final VertxOptions vertxOptions = new VertxOptions();
        EventBusOptions eventBusOptions = new EventBusOptions();
        // 本机局域网Ip
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        vertxOptions.setEventBusOptions(eventBusOptions).getEventBusOptions().setHost(hostAddress);

        HazelcastClusterManager clusterManager = new HazelcastClusterManager();

        vertxOptions.setClusterManager(clusterManager);

        Vertx.clusteredVertx(vertxOptions, res -> {
   
            Vertx result = res.result();
            result.deployVerticle(new MainClusterVerticle(), r -> {
   
                if (r.succeeded()) {
   
                    System.out.println(MainClusterVerticle.class.getName() + " --> 部署成功");
                } else {
   
                    r.cause().printStackTrace();
                    System.err.println(MainClusterVerticle.class
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值