当Crystal框架项目中需要使用消息机制,而项目规模不大、性能要求不高时,可内置启动MetaQ服务器。
分步指南
项目引入crystal-extend-metaq模块,如下:
<dependency> <groupId>com.gsoft.crystal</groupId> <artifactId>crystal-extend-metaq</artifactId> </dependency>
服务器默认参数如下:
[system] brokerId=0 hostName=192.168.1.150 numPartitions=6 serverPort=8123 dashboardHttpPort=8120 unflushThreshold=0 unflushInterval=10000 maxSegmentSize=1073741824 maxTransferSize=1048576 deletePolicy=delete,168 deleteWhen=0 0 6,18 * * ? flushTxLogAtCommit=1 stat=true ;; Update consumers offsets to current max offsets when consumers offsets are out of range of current broker's messages. ;; It must be false in production.But recommend to be true in development or test. updateConsumerOffsets=true [zookeeper] zk.zkConnect=localhost:2181 zk.zkSessionTimeoutMs=30000 zk.zkConnectionTimeoutMs=30000 zk.zkSyncTimeMs=5000 ;; Topics section [topic=test] [topic=meta-test]
可在项目src/main/resource/metaq目录下,创建service.ini文件,并将以上默认内容复制到文件中后,修改相应内容;
若项目中存在service.ini文件,则优先作为MetaQ服务启动的配置文件。
启动项目是,MetaQ服务将自动启动。
本文介绍在Crystal框架项目中如何使用消息机制,通过引入crystal-extend-metaq模块并配置MetaQ服务器,适用于小规模项目。文章提供服务器默认参数及配置文件创建指导。
178

被折叠的 条评论
为什么被折叠?



