当前位置:网站首页>MetaQ集群安装测试
MetaQ集群安装测试
2022-06-29 23:02: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
边栏推荐
- Golang code specification sorting
- The client can connect to remote MySQL
- Mysql database: the difference between drop, truncate and delete
- 均值、方差、标准差、协方差的概念及意义
- 大学里遗憾的事,希望你无怨也无悔
- nrm详解
- Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
- Mysql database: read write separation
- 基金的利润分配与税收
- 剑指 Offer 38. 字符串的排列
猜你喜欢
![The server quickly sets up the alist integrated network disk website [pagoda panel one click deployment of alist]](/img/96/3e634c173c96082881286ba402a067.png)
The server quickly sets up the alist integrated network disk website [pagoda panel one click deployment of alist]

Gnawing down the big bone - sorting (I)

微博系统中”微博评论“的高性能高可用计算架构

wirehark数据分析与取证infiltration.pacapng

地方/园区如何做好产业分析?

High performance and high availability computing architecture of "Weibo comments"

Number theory - division and blocking

Paper writing tool: latex online website
![PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记](/img/33/304e3e78f62b156d0863a41d243679.png)
PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记

软件测试 接口测试 Jmeter 5.5 安装教程
随机推荐
Software testing interface testing postman testing tool interface testing process execution interface testing interface associated environment variables and global variables built-in dynamic parameter
uniapp复制内容到剪贴板
The soft youth under the blessing of devcloud makes education "smart" in the cloud
Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]
Does rapid software delivery really need to be at the cost of security?
111. simple chat room 14: chat room client
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
Regular expressions: characters (2)
Number theory - division and blocking
Taishan Office Technology Lecture: all elements in a row have the same height
Welcome the "top ten" of the Municipal Association for science and technology • pay tribute to Lu Yi, a scientific and technological worker: an explorer guarding the transmission security of the power
Dépannage de l'étiquette: impossible d'ouvrir l'image marquée
Discussion on distributed unique ID generation scheme
Summer rainbow comes for dinner
Static keyword continuation, inheritance, rewrite, polymorphism
Uniapp copy contents to clipboard
均值、方差、标准差、协方差的概念及意义
远程沟通高效的自我总结| 社区征文
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
基金的利润分配与税收