学习电脑,计算机系统故障维护,电脑技术,电脑知识学习-就上第二电脑网
当前位置: 首页 > 电脑知识 > 电脑基础

电脑无损播放器kafka, zeromq demo

 更新时间: 2019-08-06 08:27:10   作者:第二电脑网   来源:第二电脑网   浏览数:240   我要评论

kafka: 修改bi/widows/kafka-seve-stat.bat set KAFKA_HEAP_OPTS=-Xmx512M -Xms512M<b> seve.popeties pot=9092<b> 启动zk zookeepe-seve-stat.bat ../../

 

import org.zeromq.ZMQ;

public class Publisher {

    public static void main(String args[]) {
        ZMQ.Context context = ZMQ.context(1); // 创建包含一个I/O线程的context
        ZMQ.Socket publisher = context.socket(ZMQ.PUB);
        publisher.bind("tcp://*:5555");
 
        while (!Thread.currentThread ().isInterrupted()) {
            String message = "toutiao hello";
            publisher.send(message.getBytes());
            System.out.println("sent : " + message);
        }  
 
        publisher.close();  
        context.term();  
    }  
}

 

 

import org.zeromq.ZMQ;

public class Subscriber {

    public static void main(String args[]) {  
        for (int j = 0; j < 10; j++) {
            new Thread(new Runnable(){
                public void run() {  
                    ZMQ.Context context = ZMQ.context(1);
                    ZMQ.Socket subscriber = context.socket(ZMQ.SUB);
                    subscriber.connect("tcp://127.0.0.1:5555");
                    subscriber.subscribe("toutiao".getBytes());

                    try {
                        while (true) {
                            byte[] message = subscriber.recv();
                            System.out.println(Thread.currentThread().getName() + " receive : " + new String(message));
                        }
                    } finally {
                        subscriber.close();
                        context.term();
                    }
                }
            }).start();  
        }
    }  
}

 

 


更多:电脑无损播放器kafka, zeromq demo
https://www.002pc.com/diannaojichu/691.html

你可能感兴趣的demo,zeromq,kafka

Tags:demo zeromq kafka

关于我们 - 广告合作 - 联系我们 - 免责声明 - 网站地图 - 投诉建议 - 在线投稿

  浙ICP备140365454号

©CopyRight 2008-2020 002pc.COM Inc All Rights Reserved. 第二电脑网 版权所有 联系QQ:282523118