NET Windows Kafka

Source: Internet
Author: User
Tags allkeys windows support zookeeper

NET Windows Kafka installation and use (Getting Started notes) complete solution please refer to:

Setting up and Running Apache Kafka on Windows OS

In the environmental construction process encountered two problems, listed here first, to facilitate the query: 1. \java\jre7\lib\ext\qtjava.zip was unexpected on this time. Process exited Solution:1.1 Right click on "My Computer", "Advanced system Settings", "Environment variables" 1.2 see if the value of the classpath contains qtjava.zip path, if any, the corresponding path is deleted, the problem is resolved. 2. Missing ' server ' JVM (JAVA\JRE7\BIN\SERVER\JVM--. DLL.) Solution:2.1. Copy C:\Program files\java\jdk1.6.0\jre\bin\server2.2 paste to C:\Program files\java\jre1.6.0\bin

Build the Environment

1. Installing the JDK

1.1 Installation file: http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html download server JRE.
1.2 After installation, you need to add the following environment variables (right-click "My Computer", "Advanced system Settings", "Environment variables"):

      • Java_home:c:\program Files (x86) \java\jre1.8.0_60 (this is the default installation path, if you change the installation directory during installation, fill in the changed path)
      • PATH: Add after existing value "; %java_home%\bin "

1.3 Open cmd Run "java-version" to view the current system Java version:

2. Installing zookeeper

The Kafka run depends on zookeeper, so we need to install and run the Kafka before running the zookeeper

2.1 Download installation file: http://zookeeper.apache.org/releases.html2.2 Unzip the file (this article extract to G:\zookeeper-3.4.8) 2.3 open G:\zookeeper-3.4.8\ conf, rename the zoo_sample.cfg to zoo.cfg2.4 from the text editor to open zoo.cfg2.5 to change the value of DataDir to ": \zookeeper-3.4.8\data" 2.6 Add the following system variables:
      • zookeeper_home:g:\zookeeper-3.4.8
      • Path: Add ";%zookeeper_home%\bin" after the existing value;

2.7 Run Zookeeper: Open cmd and execute

Zkserver

3. Install and run the Kafka3.1 download installation file: http://kafka.apache.org/downloads.html3.2 Unzip the file (this article extracted to G:\kafka_2.11-0.10.0.1) 3.3 open G:\kafka_ 2.11-0.10.0.1\config3.4 open from a text editor server.properties3.5 change log.dirs value to "G:\kafka_2.11-0.10.0.1\kafka-logs" 3.6 Open cmd3.7 into Kafka file directory: cd/d G:\kafka_2.11-0.10.0.1\3.8 input and execute to open Kafka:
. \bin\windows\kafka-server-start.bat. \config\server.properties

4. Create topics4.1 open cmd and enter G:\kafka_2.11-0.10.0.1\bin\windows4.2 to create a topic:
Kafka-topics.bat--create--zookeeper localhost:2181--replication-factor 1--partitions 1--topic test

5. Open a producer:
cd/d G:\kafka_2.11-0.10.0.1\bin\windowskafka-console-producer.bat--broker-list localhost:9092--topic test

6. Open a consumer:
CD/D G:\kafka_2.11-0.10.0.1\bin\windows
Kafka-console-consumer.bat--zookeeper localhost:2181--topic test
You can then enter the message in the Producer Console window. After the message is entered, the consumer window will soon display the message sent by producer:

At this point, the construction of the Kafka operating environment is completed:-)

Web management aspects (formal OPS deployment):

Someone online says Kafka manage

. NET SDK Aspects:

Someone suggested: Https://github.com/Microsoft/CSharpClient-for-Kafka (Microsoft provides the SDK, read the source of the personal feeling somewhat complex)


And also
Kafka-net This feeling will be much simpler (read the source feeling some task writing does not like)

Recommendation: Kafka-net simple and easy to use.

Address: Https://github.com/Jroland/kafka-net

The above SDK can search for NuGet to view open source addresses and latest release packages, but there are many other options for the. NET SDK.

Personal development tools (Windows support), Windows development environment uses

Kafkatool

: http://www.kafkatool.com/download.html

Kafka-net SDK uses demo

Reference Source: http://www.cnblogs.com/Wulex/p/5619425.html

For details, please see the official open source address demo:https://github.com/jroland/kafka-net

Kafkaproducer Program:

Class Program {static void Main (string[] args) {do {produce (Getka                Fkabroker (), Gettopicname ());            System.Threading.Thread.Sleep (3000);        } while (true); } private static void produce (string broker, String topic) {var options = new Kafkaoptions (New U            RI (broker));            var router = new Brokerrouter (options);            var client = new Producer (router);            var currentdatetime =datetime.now;            var key = CurrentDatetime.Second.ToString ();            var events = new[] {new Message ("Hello World" + Currentdatetime, Key)}; Client. Sendmessageasync (topic, events).            Wait (1500); Console.WriteLine ("Produced:key: {0}. Message: {1}", Key, Events[0].            Value.toutf8string ()); using (client) {}} private static string Getkafkabroker () {string kafkabroker = string.            Empty; Const string KafkabrokerkeYname = "Kafkabroker"; if (! ConfigurationManager.AppSettings.AllKeys.Contains (Kafkabrokerkeyname)) {Kafkabroker = "http://l            ocalhost:9092 ";            } else {kafkabroker = Configurationmanager.appsettings[kafkabrokerkeyname];        } return Kafkabroker; } private static String Gettopicname () {string topicname = string.            Empty;            Const string topicnamekeyname = "Topic"; if (! ConfigurationManager.AppSettings.AllKeys.Contains (Topicnamekeyname)) {throw new Exception ("Key            \ "" + Topicnamekeyname + "\" not found in Config file--configuration/appsettings ");            } else {topicname = Configurationmanager.appsettings[topicnamekeyname];        } return topicname; }    }

4.KafkaConsumer Program:

Class Program {static void Main (string[] args) {Consume (Getkafkabroker (), Gettopicname ()); } private static void consume (string broker, String topic) {var options = n            EW Kafkaoptions (new Uri (broker));            var router = new Brokerrouter (options);            var consumer = new Consumer (new Consumeroptions (topic, router)); Consume returns a blocking IEnumerable (Ie:never ending stream) foreach (Var message in consumer. Consume ()) {Console.WriteLine ("Response:partition {0},offset {1}: {2}", Me Ssage. Meta.partitionid, message. Meta.offset, message.            Value.toutf8string ()); }} private static string Getkafkabroker () {string kafkabroker = string.            Empty;            var kafkabrokerkeyname = "Kafkabroker"; if (!  ConfigurationManager.AppSettings.AllKeys.Contains (Kafkabrokerkeyname)) {              Kafkabroker = "http://localhost:9092";            } else {kafkabroker = Configurationmanager.appsettings[kafkabrokerkeyname];        } return Kafkabroker; } private static String Gettopicname () {string topicname = string.            Empty;            var topicnamekeyname = "Topic"; if (! ConfigurationManager.AppSettings.AllKeys.Contains (Topicnamekeyname)) {throw new Exception ("Key            \ "" + Topicnamekeyname + "\" not found in Config file--configuration/appsettings ");            } else {topicname = Configurationmanager.appsettings[topicnamekeyname];        } return topicname; }    }

5.Consumer results:

NET Windows Kafka

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.