当前位置:网站首页>MetaQ集群安裝測試
MetaQ集群安裝測試
2022-06-29 23:22:00 【星哥玩雲】
1,ZooKeeper集群安裝,可以參考 ZooKeeper集群環境搭建實踐 http://www.linuxidc.com/Linux/2013-04/83562.htm
2,下載https://github.com/killme2008/Metamorphosis/tree/metamorphosis-all-1.4.6.2,如果不想自己編譯可以直接下載http://fnil.net/downloads/index.html,我這裏選擇自己編譯,主要是以後如果出現問題自己可以修改其源碼,重新編譯
3,maven編譯,maven環境自己搜索配置好,下載all項目後需要編譯其子項目metamorphosis-server-wrapper。dos環境進入其目錄下mvn eclipse:eclipse,完成後導入到eclipse,用eclipse插件編譯。或者直接dos該目錄下執行mvn clean install -Dmaven.test.skip=true。完成後target目錄下生產其jar包;
可以在工程創建lib文件夾,輸入以下命令:mvn dependency:copy-dependencies -DoutputDirectory=lib (不加DoutputDirectory會默認輸出到targed/dependency下)。再把install的jar包也copy到lib下。
4,完成編譯後上傳到服務器
需要修改conf/server.ini文件
[system]brokerId=2
numPartitions=1
serverPort=8123
ashboardHttpPort=8120
unflushThreshold=0
unflushInterval=10000
maxSegmentSize=1073741824
maxTransferSize=1048576
deletePolicy=delete,168
deleteWhen=0 0 6,18 * * ?
flushTxLogAtCommit=1
stat=true
dataPath=/data1/metaq/data
dataLogPath=/data1/metaq/log
[zookeeper]
zk.zkConnect=192.168.1.1:2181,192.168.1.2:2181,192.168.1.3:2181
zk.zkSessionTimeoutMs=30000
zk.zkConnectionTimeoutMs=30000
zk.zkSyncTimeMs=5000
;; Topics section
[topic=test]
[topic=meta-test]
集群的話需要修改上面標紅部分,brokerId保證每個服務器節點上不一樣就行
dataPath,dataLogPath如果自己制定,需要每臺服務器mkdir
分發到個節點,在每臺節點的bin下都執行metaServer.sh start
需要停止時執行metaServer.sh stop
查看狀態sh metaServer.sh status
5,應用例子
package com.test.metaq;
import Java.util.concurrent.Executor;
import com.taobao.metamorphosis.Message; import com.taobao.metamorphosis.client.MessageSessionFactory; import com.taobao.metamorphosis.client.MetaClientConfig; import com.taobao.metamorphosis.client.MetaMessageSessionFactory; import com.taobao.metamorphosis.client.consumer.ConsumerConfig; import com.taobao.metamorphosis.client.consumer.MessageConsumer; import com.taobao.metamorphosis.client.consumer.MessageListener; import com.taobao.metamorphosis.exception.MetaClientException; import com.taobao.metamorphosis.utils.ZkUtils.ZKConfig;
public class AsyncConsum {
public static void main(String[] args) { final MetaClientConfig metaClientConfig = new MetaClientConfig(); final ZKConfig zkConfig = new ZKConfig(); zkConfig.zkConnect = "10.168.140.48:2181"; metaClientConfig.setZkConfig(zkConfig); MessageSessionFactory sessionFactory = null; try { sessionFactory = new MetaMessageSessionFactory(metaClientConfig); } catch (MetaClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } final String topic = "test"; final String group = "meta-example"; MessageConsumer consumer = sessionFactory.createConsumer(new ConsumerConfig(group)); try { consumer.subscribe(topic, 1024 * 1024, new MessageListener() { public void recieveMessages(Message message) { System.out.println("Receive message " + new String(message.getData())); } public Executor getExecutor() { return null; } }); consumer.completeSubscribe(); } catch (MetaClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
}
package com.test.metaq;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;
import com.taobao.metamorphosis.Message; import com.taobao.metamorphosis.client.MessageSessionFactory; import com.taobao.metamorphosis.client.MetaClientConfig; import com.taobao.metamorphosis.client.MetaMessageSessionFactory; import com.taobao.metamorphosis.client.producer.MessageProducer; import com.taobao.metamorphosis.client.producer.SendResult; import com.taobao.metamorphosis.exception.MetaClientException; import com.taobao.metamorphosis.utils.ZkUtils.ZKConfig;
public class Products {
public static void main(String[] args) { final MetaClientConfig metaClientConfig = new MetaClientConfig(); final ZKConfig zkConfig = new ZKConfig(); zkConfig.zkConnect = "10.168.140.48:2181"; metaClientConfig.setZkConfig(zkConfig); MessageSessionFactory sessionFactory = null; try { sessionFactory = new MetaMessageSessionFactory(metaClientConfig); } catch (MetaClientException e) { e.printStackTrace(); } MessageProducer producer = sessionFactory.createProducer(); final String topic = "test"; producer.publish(topic); BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); String line = "qiujinyong"; try { while ((line = reader.readLine()) != null) { SendResult sendResult = producer.sendMessage(new Message(topic, line.getBytes())); if (!sendResult.isSuccess()) { System.err.println("Send message failed,error message:" + sendResult.getErrorMessage()); } else { System.out.println("Send message successfully,sent to " + sendResult.getPartition()); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MetaClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }
}
}
打包test.jar後,傳服務器上 java -cp test.jar com.test.metaq.Products 命令行輸入message
打包test.jar後,傳服務器上 java -cp test.jar com.test.metaq.AsyncConsum 命令行會接收到message
边栏推荐
- Polymorphism of laravel association model
- flutter 插件版本冲突的解决方法
- SYSTEMd debugging
- Principe de réalisation de l'agent dynamique
- Solr基础操作
- InfluxDB时序数据库系统
- Mysql database: storage engine
- Does Australia require that PVC plastic sheets comply with as/nzs 1530.3 with a flame spread index of 0?
- [从零开始学习FPGA编程-51]:高阶篇 - 基于IP核的FPGA开发- 什么是FPGA IP核(软核、固核、硬核)与学习方法
- Leetcode 1385. Distance value between two arrays
猜你喜欢

Processing of error b6267342 reported by AIX small machine in production environment

Constexpr function

C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
![Project 1 - buffer pool [cmu 15-445645] notes](/img/33/304e3e78f62b156d0863a41d243679.png)
Project 1 - buffer pool [cmu 15-445645] notes

Vs cannot locate program input point to DLL

软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数

写论文工具:LaTex在线网站

Sword finger offer 38 Arrangement of strings

缓冲流练习

InfluxDB时序数据库系统
随机推荐
Wechat applet: (update) cloud development wechat group contacts
Unity Pac Man games, maze implementation
Vs cannot locate program input point to DLL
提供有效的绩效评估
Node data collection and remote flooding transmission of label information
Cacti最大监控数测试
远程沟通高效的自我总结| 社区征文
Project 1 - buffer pool [cmu 15-445645] notes
基于OpenStack的虚拟机在线迁移
C language tutorial – -6 loop statement
Open source the Ernie tiny lightweight technology of "Wenxin big model", which is accurate and fast, with full effect
Principe de réalisation de l'agent dynamique
Pytest initializing and cleaning up the environment
服务器快速搭建AList集成网盘网站【宝塔面板一键部署AList】
js函数相关的复习
flutter 插件版本冲突的解决方法
GWD: rotating target detection based on Gaussian Wasserstein distance | ICML 2021
Is it safe to open a stock account? Shanghai stock account opening.
Mysql database: read write separation
2022 PMP project management examination agile knowledge points (5)