Vertx集群配置

article/2025/8/21 3:49:21

vertx集群配置

1. pom文件中引入vertx-hazelcast jar

<dependency><groupId>io.vertx</groupId><artifactId>vertx-hazelcast</artifactId><version>${vertx-version}</version>
</dependency>

目前是3.3.3版本

2. resources内加入hazelcast的配置文件cluster.xml

默认vertx会去找vertx-hazelcast.jar内的default-cluster.xml
default-cluster.xml
如果需要自定义配置文件,需要将其放在classpath下,并且命名为cluster.xml,即打成fat包后在主目录下面。
fat包的cluster.xml
eclipse的java项目只需将default-cluster.xml文件copy一份到resources目录内,并修改名字为cluster.xml,打包的时候就会打到classpath的主目录下。
cluster.xml

3. cluster.xml配置

hazelcast的集群有3种方式

  1. 广播multicast模式
<multicast enabled="true"><multicast-group>224.2.2.3</multicast-group><multicast-port>54327</multicast-port>
</multicast>

如果为true,同一个网段内的vertx实例会自动发现,并集群
2. ip地址tcp-ip模式

<tcp-ip enabled="true"><interface>192.168.1.28</interface><interface>192.168.1.27</interface><interface>192.168.1.26</interface>
</tcp-ip>

需要把要集群的ip地址列在这里
3. aws亚马逊云集群模式

<aws enabled="false"><access-key>my-access-key</access-key><secret-key>my-secret-key</secret-key><!--optional, default is us-east-1 --><region>us-west-1</region><!--optional, default is ec2.amazonaws.com. If set, region shouldn't be set as it will override this property --><host-header>ec2.amazonaws.com</host-header><!-- optional, only instances belonging to this group will be discovered, default will try all running instances --><security-group-name>hazelcast-sg</security-group-name><tag-key>type</tag-key><tag-value>hz-nodes</tag-value>
</aws>

一般采用第二种ip地址tcp-ip模式,将其它模式置为false。整体的cluster.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.2.xsd"xmlns="http://www.hazelcast.com/schema/config"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><properties><property name="hazelcast.mancenter.enabled">false</property><property name="hazelcast.memcache.enabled">false</property><property name="hazelcast.rest.enabled">false</property><property name="hazelcast.wait.seconds.before.join">0</property></properties><group><name>dev</name><password>dev-pass</password></group><management-center enabled="false">http://localhost:8080/mancenter</management-center><network><port auto-increment="true" port-count="10000">5701</port><outbound-ports><!--Allowed port range when connecting to other nodes.0 or * means use system provided port.--><ports>0</ports></outbound-ports><join><multicast enabled="false"><multicast-group>224.2.2.3</multicast-group><multicast-port>54327</multicast-port></multicast><tcp-ip enabled="true"><interface>192.168.1.28</interface><interface>192.168.1.27</interface><interface>192.168.1.26</interface></tcp-ip><aws enabled="false"><access-key>my-access-key</access-key><secret-key>my-secret-key</secret-key><!--optional, default is us-east-1 --><region>us-west-1</region><!--optional, default is ec2.amazonaws.com. If set, region shouldn't be set as it will override this property --><host-header>ec2.amazonaws.com</host-header><!-- optional, only instances belonging to this group will be discovered, default will try all running instances --><security-group-name>hazelcast-sg</security-group-name><tag-key>type</tag-key><tag-value>hz-nodes</tag-value></aws></join><interfaces enabled="false"><interface>10.10.1.*</interface></interfaces><ssl enabled="false"/><socket-interceptor enabled="false"/><symmetric-encryption enabled="false"><!--encryption algorithm such asDES/ECB/PKCS5Padding,PBEWithMD5AndDES,AES/CBC/PKCS5Padding,Blowfish,DESede--><algorithm>PBEWithMD5AndDES</algorithm><!-- salt value to use when generating the secret key --><salt>thesalt</salt><!-- pass phrase to use when generating the secret key --><password>thepass</password><!-- iteration count to use when generating the secret key --><iteration-count>19</iteration-count></symmetric-encryption></network><partition-group enabled="false"/><executor-service name="default"><pool-size>16</pool-size><!--Queue capacity. 0 means Integer.MAX_VALUE.--><queue-capacity>0</queue-capacity></executor-service><multimap name="__vertx.subs"><!--Number of backups. If 1 is set as the backup-count for example,then all entries of the map will be copied to another JVM forfail-safety. 0 means no backup.--><backup-count>1</backup-count></multimap><map name="__vertx.haInfo"><!--Number of backups. If 1 is set as the backup-count for example,then all entries of the map will be copied to another JVM forfail-safety. 0 means no backup.--><backup-count>1</backup-count><!--Maximum number of seconds for each entry to stay in the map. Entries that areolder than <time-to-live-seconds> and not updated for <time-to-live-seconds>will get automatically evicted from the map.Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
--><time-to-live-seconds>0</time-to-live-seconds><!--Maximum number of seconds for each entry to stay idle in the map. Entries that areidle(not touched) for more than <max-idle-seconds> will getautomatically evicted from the map. Entry is touched if get, put or containsKey is called.Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
--><max-idle-seconds>0</max-idle-seconds><!--Valid values are:NONE (no eviction),LRU (Least Recently Used),LFU (Least Frequently Used).NONE is the default.--><eviction-policy>NONE</eviction-policy><!--Maximum size of the map. When max size is reached,map is evicted based on the policy defined.Any integer between 0 and Integer.MAX_VALUE. 0 meansInteger.MAX_VALUE. Default is 0.--><max-size policy="PER_NODE">0</max-size><!--When max. size is reached, specified percentage ofthe map will be evicted. Any integer between 0 and 100.If 25 is set for example, 25% of the entries willget evicted.--><eviction-percentage>25</eviction-percentage><!--While recovering from split-brain (network partitioning),map entries in the small cluster will merge into the bigger clusterbased on the policy set here. When an entry merge into thecluster, there might an existing entry with the same key already.Values of these entries might be different for that same key.Which value should be set for the key? Conflict is resolved bythe policy set here. Default policy is PutIfAbsentMapMergePolicyThere are built-in merge policies such ascom.hazelcast.map.merge.PassThroughMergePolicy; entry will be added if there is no existing entry for the key.com.hazelcast.map.merge.PutIfAbsentMapMergePolicy ; entry will be added if the merging entry doesn't exist in the cluster.com.hazelcast.map.merge.HigherHitsMapMergePolicy ; entry with the higher hits wins.com.hazelcast.map.merge.LatestUpdateMapMergePolicy ; entry with the latest update wins.--><merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy></map><!-- Used internally in Vert.x to implement async locks --><semaphore name="__vertx.*"><initial-permits>1</initial-permits></semaphore></hazelcast>

4. 集群方式运行fat.jar包

java -jar F:\work\i5xwxpro\target\i5xwxpro.jar -cluster

分别在对应的服务器上执行命令即可。

-cluster即是代表集群方式启动

5. nginx负载均衡

    upstream web{server 192.168.1.28:8080;server 192.168.1.27:8080;server 192.168.1.26:8080;}

nginx将请求负载到不同的vertx服务器即可


http://chatgpt.dhexx.cn/article/S5enX1Hw.shtml

相关文章

基于vertx-web-sstore-redis的改造实现vertx http应用的分布式session

1. vertx 自身基于redis的分布式session的不足 vertx 本身有redis的分布式session的实现。只需要引入如下依赖 <dependency><groupId>io.vertx</groupId><artifactId>vertx-web-sstore-redis</artifactId><version>4.1.4</version>…

Spring调用vertx异步service Interface

Spring调用Vertx异步service Interface 情景原理实现工程结构说明目录结构样例代码example-vertx-interfacepom依赖代码 example-vertx-clusterpom依赖代码 lm-spring-vertx-ebclientpom依赖代码VertxEBClientScanVertxEBClientScannerRegisterVertxEBProxyBeanDefinitionRegis…

Vert.x - SpringBoot 整合 vertx 使用 thymeleaf、freemarker 模板引擎

一、模板引擎 在 SpringMVC 项目中使用模板引擎&#xff0c;使用较多的应该是 thymeleaf 及 freemarker 了吧&#xff0c;虽然现在前后端分离的浪潮已经席卷而来&#xff0c;但对于 SEO 或者 页面静态话来说&#xff0c;后端的模板引擎还是具有一定的作用力。本篇文章继续上篇…

Vert.x - SpringBoot 整合 vertx

一、vertx 前面的文章讲解了 vertx 的简介及 vertx-web 的路由&#xff0c;看过的小伙伴应该对 vertx 有了一定的了解&#xff0c;从前面的演示来看&#xff0c;都是单独使用的 vertx &#xff0c;对于目前的后端来说 SpringBoot 可是一个非常火热的框架&#xff0c;那如果将 …

Vert.x - vertx-web 路由讲解总结

一、vertx-web 上篇文章我们对 vertx 进行了简单的介绍&#xff0c;并使用 vertx-web 实践了 restFul 接口的书写&#xff0c;本篇文章接着上篇继续讲解 vertx-web 的路由。 下面是上篇文章的地址&#xff1a; https://blog.csdn.net/qq_43692950/article/details/123955368 …

vertx的http服务实现分布式session

vetrx是基于netty封装的java网络编程框架&#xff0c;比netty开发较为简单&#xff0c;在其基础上提供很多有用功能&#xff0c;能在较短的时间内开发一个http服务器&#xff0c;或其他网络服务。今天我们展示下如何为vertx开发http网关实现分布式session,实现参考spring sessi…

Vert.x入门1 —— 《基础概念》

一、什么是Vertx Vert.x 在JVM上构建响应式应用程序的工具包&#xff0c;Vert.x不是框架而是工具包。Vert.x基于Netty项目&#xff0c;该项目是JVM的高性能异步网络库。 此描述中有三个重要点&#xff1a;工具包&#xff0c;响应式和“在JVM上”。 首先&#xff0c;Vert.x是…

Vertx快速入门参考

Vertx学习 什么是vertx&#xff1f; Vert.x最大的特点就在于异步&#xff08;底层基于Netty&#xff09;&#xff0c;通过事件循环&#xff08;EventLoop&#xff09;来调起存储在异步任务队列&#xff08;CallBackQueue&#xff09;中的任务&#xff0c;大大降低了传统阻塞模…

Vertx入门学习(含代码)

Vertx入门学习 一、Vertx是什么&#xff1f;二、Vertx基本概念三、Vertx能干什么&#xff1f;四、Vertx的技术体系五、快速体验&#xff1a;搭建一个简单的Vertx项目并输出Hello World六、单元测试总结 一、Vertx是什么&#xff1f; github: https://github.com/vert-x3 官网&…

Vert.x(vertx) 简明介绍

摘要 Vert.x最大的特点就在于异步&#xff08;底层基于Netty&#xff09;&#xff0c;通过事件循环&#xff08;EventLoop&#xff09;来调起存储在异步任务队列&#xff08;CallBackQueue&#xff09;中的任务&#xff0c;大大降低了传统阻塞模型中线程对于操作系统的开销。因…

Vertx学习一:这玩意是到底是个啥

Vertx&#xff0c;融合Java、Ruby、Python等语言的高性能架构&#xff0c;架构师必读 原文链接&#xff1a; http://www.360doc.com/content/18/0203/14/39530679_727432611.shtml 目录&#xff1a; 一、Vert.x简介 二、Vert.x原理解析 三、Vert牛刀小试 四、Vert应用实践 五…

【java】vertx从入门到放弃——入门(四)Codec

什么是Codec&#xff1f;概念这个玩意我是真不想说&#xff0c;毕竟我没有找到具体的概念&#xff0c;我自己大致的理解就是&#xff0c;用EventBus传输类的时候&#xff0c;对这个类进行序列化和反序列化的东西&#xff0c;因为vertx使用json进行传输&#xff0c;所以这个玩意…

Android thinker

国家虽安&#xff0c;忘战必危&#xff0c; Android虽爽&#xff0c;不学则忙&#xff0c;老夫纵横江湖数十载&#xff0c;深谙世事之难料&#xff0c;顾。。 ok&#xff0c;ok 不装比了&#xff0c;进入正题&#xff0c;今天要讲的是Android 热修之 thinker。 在研究这个之前…

ESP32-CAM AI THINKER 引脚排列:GPIO 用法说明

ESP32-CAM 是一款开发板,带有一个 ESP32-S 芯片、一个 OV2640 摄像头、microSD 卡插槽和几个用于连接外设的 GPIO。在本指南中,我们将介绍 ESP32-CAM GPIO 以及如何使用它们。 引脚排列图 下图显示了 ESP32-CAM AI-Thinker 的引脚排列图。 电路原理示意图 下图显示了 ESP…

Thinkpad 各系列简介

ThinkPad 各系列简介 如果提到商务笔记本&#xff0c;大家一定会想到凭借坚固和可靠的特性在业界享有很高声誉ThinkPad笔记本电脑&#xff0c;以及ThinkPad那经典的键盘红点设计和纯黑低调的外表。 在这里我就简单介绍一下ThinkPad的各系列产品。 Thinkpad名称来历 “ThinkP…

python thinker canvas create_arc 使用详解

版权声明&#xff1a;本文为博主原创文章&#xff0c;遵循 CC 4.0 BY-SA 版权协议&#xff0c;转载请附上原文出处链接和本声明。 本文链接&#xff1a;https://blog.csdn.net/A757291228/article/details/106739556 ———————————————— 版权声明&#xff1a;本文…

二、让界面动起来,Python基于thinker实现的简单的俄罗斯方块小游戏

文章目录 界面动起来定时刷新页面移动俄罗斯方块 界面动起来 **功能&#xff1a;**如何让方块「动起来」? 分析过程&#xff1a; 要想让方块动起来&#xff0c;需要实现以下两点&#xff1a; 定时刷新页面移动页面内部的俄罗斯方块 定时刷新页面 实现定时刷新页面&#xff…

三、生成随机方块,Python基于thinker实现的简单的俄罗斯方块小游戏

文章目录 生成第一步&#xff1a;随机生成方块对象第二步&#xff1a;修改游戏运行方法 固定第一步&#xff1a;记录固定的方块第二步&#xff1a;修改check_move方法 左右移动第一步&#xff1a;左右移动方块第二步&#xff1a;绑定键盘 旋转第一步&#xff1a;添加旋转方法第…

【G-thinker】G-thinker部分源码解析

一、main 子图匹配程序run.cpp中主要使用到worker.h和comper.h分别对应线程和进程单位&#xff0c;接下来我们从main函数入手解析源码 从主函数可以看到&#xff0c;子图匹配程序中GMatchWorker继承了worker&#xff0c;主函数声明了workerparams并且传入了路径和线程参数&am…

python用thinker库制作一个进制转换器(可打包exe)

进制类型分为&#xff1a; 二进制 字母B表示 八进制 字母O表示 十进制 字母D表示 十六机制 字母H表示 进制转换之间很麻烦&#xff0c;还得计算&#xff0c;如果可以做一个进制转换器多nice&#xff0c;其实也不难&#xff0c;就利用一个tkinter库就能制作&#xff0c;废话不多…