kafka- shown signs

Message Queue MQ

Is added to the message queue Queue Message Queue message, the message is transmitted to a container, the production and consumption provides API for storing and retrieving messages.

Message queues in two ways: peer (p2p), publish-subscribe (pub / sub)

The same point: Production message into the queue, are acquired from the message queue

Different points: p2p mode is a message can only be consumed once, after the news consumption does not exist, such as phone calls;

    The subscription model is a news release can be consumed N times, and at the same time can be more consumer spending, such as public micro-channel number;

 

kafka Profile

kafka is a publish-subscribe messaging system, has the following characteristics:

High throughput: support for millions of messages per second grade production and consumption

Persistence: The message store has a comprehensive mechanism to ensure lasting security news

Distributed: Distributed expansion and fault tolerance; kafka will copy data to several other servers, if linked to a server, automatically switches to the other servers.

 

kafka is a middleware message;

Used to handle active data, such as logging in, browsing

 

kafka composition

kafka Service

topic: topic, category represents the message, such as sports, entertainment

broker: message broker, is a node in the cluster, responsible for storing data, topic can partition storage

partition: the packet on the physical topic, a topic in a partition is divided into n broker in

message: message, each message is assigned a corresponding Partition, a need for a mapping relationship

 

kafka-related services

producer: news producer

consumer: Consumer news

zookeeper: coordination kafka normal operation

 

broker configuration

Kafka a broker on behalf of a service profile for kafka profile: server.properties

1. In order to reduce the number of disk writes, Kafka will first buffer up message, when the message reaches a certain number, or after a certain time, and then to flush the disk

The corresponding configuration

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk. 
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks. 
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000  <=========

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000  <=========
 

 

2. The message will be deleted automatically stored for a certain time, the default seven days, 168 hours

The corresponding configuration

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168  

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according 
# to the retention policies
log.retention.check.interval.ms=300000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.
# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.
log.cleaner.enable=false

 

producer Configuration

News producer, the configuration file: producer.properties

1. partitioner.class: You can customize the partitioning method, designated users to write their own algorithms

2. producer.type = sync: sending a message is synchronous or asynchronous, synchronous response is received after sending a re-issued message is just sent asynchronously

3. Asynchronous transmission support batch transmission, to increase the transmission efficiency, the first message buffer memory and sent out one time, the corresponding parameters queue.buffering.max.ms =; queue.buffering.max.messages =; default 5000 and said to 10000

 

consumer Configuration

Profile: consumer.properties

1. group.id = test-consumer-group: every consumer belongs to a group, here designated group id

2. kafka with the consumer in the form of grouping related messages,

Groups, the same of different groups of consumer data, independently of each other;

Within the group, group members consume the same data at the same time there can be only a consumer "online", and at the same time the consumer can only consume a topic of a partition, a partition consumption is completed, you can also consume another partition

  // So, corresponds to a topic, we do not recommend more than the number of partition members of the same group to spend this topic, because while there can be only one consumer online, members can take up to partition

3. a consumer to open multiple threads, a thread is equivalent to a consumer

(This is a Topic Kafka used for broadcast messages (sent to all Consumer) and unicast (one issue Consumer) means. 
A Topic may correspond to a plurality of Consumer Group. To implement the broadcast, as long as each Consumer there is a separate group on it. 
to achieve as long as all of unicast Consumer. you can also use Consumer group Consumer group free in the same group in without the need to send a message to a different Topic many times.)

 

partition

Each partition in the storage level is append log file, the new message is appended to the end of the file;

Each message has a position in the log file called offset (offset);

The more partition means you can accommodate more consumer, effectively enhance the ability of concurrent consumption;

Business partition increases topic, increase the amount of data partition

 

message

Three attributes:

offset: long type, on behalf of the message number in the partition, or id

MessageSize: int32, size = byte

data: specific content

 

broker configuration in detail

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in Writing, Software 
# Distributed an under at The License IS Distributed ON AN " AS IS " BASIS, 
# the WITHOUT WARRANTIES OR CONDITIONS OF the ANY the KIND, either Express or tIMPLIED. 
# See at The License for at The specific Language Governing the Permissions and 
# Limitations an under at The License. 
See kafka.server.KafkaConfig # for Additional the Details and Defaults 

############################# Server Basics ####### ###################### 

##################################################################################
# Broker is to deploy an instance of kafka and kafka in a cluster, each kafka must have a broker.id 
# and the unique id, and it must be an integer 
######################################### ######################################### 
broker.id = 10 

################### the socket Server Settings ############################# ########## 

# at The address at The socket Server Listens ON . It by Will GET at The value returned from  
# java.net.InetAddress.getCanonicalHostName () IF not the Configured. 
# the FORMAT: 
# in the Listeners = SECURITY_PROTOCOL: // host_name: Port 
# the EXAMPLE: 
# in the Listeners = PLAINTEXT: // your.host.name : 9092 
# in the Listeners = PLAINTEXT: // : 9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

##################################################################################
#The number of threads handling network requests
# 默认处理网络请求的线程个数 3个
##################################################################################
num.network.threads=3
################################################## ################################ 
# of threads at the Number the disk doing the I / O 
# perform disk IO operations default thread number 8 
############################################### ################################### 
num.io.threads = . 8 

######## ################################################## ######################## 
# the send at the buffer (SO_SNDBUF) used by Server at the socket 
buffer size for transmission data # socket used by the service, the default 100kb 
################################################# ################################# 
socket.send.buffer.bytes = 102400 

######## ################################################## ######################## 
# at the receive buffer (SO_SNDBUF) used by Server at the socket 
carried out using the service # socket receive buffer size of the data, the default 100kb
################################################## ################################ 
socket.receive.buffer.bytes = 102400 

######### ################################################## ####################### 
# at the maximum size of that at the socket a Request Server by Will the accept (Protection Against OOM) 
# socket service can accept a maximum of requested amount, to prevent OOM (Out of memory) memory overflow, the default value: 100m 
# (should be the maximum size of a request socker server can accept, the default is 100M) 
########### ################################################## ##################### 
socket.request.max.bytes = 104857600 

#################### ######### log Basics (data relevant part, kafka data is called log) ########################### ##

################################################## ################################ 
# Directories of List a comma Seperated Store log Files to an under Which 
a comma separated # the list of directories for storing the received data kafka 
###################################### ############################################ 
log.dirs = / Home / uplooking / Data / Kafka 

############################################ ###################################### 
# at The default Number The Partitions of log per Topic. More Partitions Greater the allow 
# Parallelism for consumption, But the this by Will Also the Result in More Files across 
# at The Brokers. 
each topic of the partition of the partition number corresponding to log #, the default one. More consumption will increase the number of partition 
# parallelism, but also lead to more file transfer in kafka cluster 
# (partition is distributed storage, equivalent to a few separate data for storage, that is, divided block partitioning means partitions) 
########################################### ####################################### 
num.partitions = . 1 

###### ################################################## ########################## 
# of Threads at The Number The per the Data Directory to BE Used for log the Startup and Recovery AT AT Flushing the shutdown. 
# This value iS Recommended to BE Increased for Installations with the data dirs located block in RAID Array. 
# each directory for data recovery and data at startup kafka number of threads to refresh the data when it is closed. If kafka data stored in the disk array 
# recommended that this value can be adjusted higher. 
################################################## ################################
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy (数据刷新策略)#############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs(平衡) here:
#    1. Durability 持久性: Unflushed data may be lost if you are not using replication.
#    2. Latency 延时性: Very large flush intervals may lead to latency spikes when the flush does occur asBE A of Lot Will there Data to the flush. 
#     . 3 Throughput Throughput:. the flush of The IS . GeneRally Operation The MOST expensive, and the flush interval The A Small On May Lead seeks to exceessive 
# One of The Settings below to the allow the flush Configure The Policy to the flush data After A period of time or 
# Every N messages (or both) This CAN bE DONE Globally and Overridden A per oN. - . Topic basis 
# Kafka only to develop a data message number of pieces and the number of time intervals based on the refresh strategy, without size options, these two options can choose to configure a 
# of course, be both configured, by default, both configured with the following configuration. 

Of The Number of messages to # Accept Forcing A before the flush of Data to Disk 
# flushed to disk message bar a threshold number of message 
# log.flush.interval.messages = 10000 

# of The Time of maximum AMOUNT CAN SIT A Messagein A Force A log before the flush WE 
# flushed to disk generates a message log file data interval 
# log.flush.interval.ms = 1000 

################### ########## Log retention policy (data retention policies) ############################# 

# at The following configurations control the disposal (cleaning) of log segments (fragment). of The Policy CAN 
# BE SET to Delete Segments After A period of Time, or After A GIVEN size has accumulated (cumulative). 
# A segment Will BE deleted WHENEVER (whether what time) * * either of THESE criteria (standard) are Met. Deletion Always the happens 
# from the End of the log. 
# following configuration control data segments for cleaning, as long as one of the policies (time-based or size) , fragmentation will be deleted 

# at the Minimum Age of File A log to bE eligible forDeletion 
# time-based policy, deletion time log data, the default save seven days 
log.retention.hours = 168 

# A size -based Retention Policy for logs. Segments are Pruned from at The log AS  Long  AS at The Remaining 
# Segments Don ' t below log.retention.bytes drop.. 1G 
# size based policy,. 1G 
# log.retention.bytes = 1073741824 

# a log of the maximum segment size of File. the When the this size iS Reached a new new log segment Will BE Created. 
# data points piece strategy 
log.segment.bytes = 1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies 5分钟
# 每隔多长时间检测数据是否达到删除条件
log.retention.check.interval.ms=300000

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=uplooking01:2181,uplooking02:2181,uplooking03:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000

 

Guess you like

Origin www.cnblogs.com/yanshw/p/11468623.html
Recommended