consumption only once, the same partition will only bind one consumer information.5, if a consumer hangs, consumer and partition binding information will be reassigned, as far as possible to ensure load balance6, if the number of consumer is greater than the number of partitions, will cause the redundant part of the t
1. Start the production and consumption process using 127.0.0.1:
1) Start the producer process:
bin/kafka-console-producer.sh--broker-list 127.0.0.1:9092--topic test
Input message:
This is MSG
Producer Process Error:
[2016-06-03 11:33:47,934] WARN Bootstrap broker 127.0.0.1:9092 Disconnected (org.apache.kafka.clients.NetworkClient)
[2016-06-03 11:33:49,554] W
Logger = Loggerfactory.getlogger ( This. GetClass ()); @KafkaListener (Topics= {"Test"}) Public voidListen (consumerrecordrecord) {Logger.info ("Kafka key:" +Record.key ()); Logger.info ("Kafka Value:" +Record.value (). toString ()); }}Tips1) I did not describe how to install the configuration Kafka, the best way to configure
); Mapconsumerconnector.createmessagestreams (map); List); //Create List of 4 threads to consume from each of the partitionsExecutorservice executor = Executors.newfixedthreadpool (4); //consume the messages in the threads for(FinalKafkastreamstream:streams) {Executor.submit (NewRunnable () { Public voidrun () { for(Messageandmetadata msgandmetadata:stream) {//Process Message (Msgandmetadata.message ())System.out.println ("topic:" +msgandmetadata.topic ()); Message Message=(Message) msgandmeta
to auto-commit interval "" " consumer=kafkaconsumer (Self._topic,bootstrap_servers=self._bootstrap_server, group_id=self._groupId,client_id=self._clientId,enable_auto_commit=True, auto_commit_ Interval_ms=5000,value_deserializer=lambdam:json.loads (M.decode (' Utf-8 '))) "" " There is no need to display theThe subscription function is called, the theme is specified when initializing the Kafkaconsumer object, and the subscription function is au
to auto-commit interval "" " consumer=kafkaconsumer (Self._topic,bootstrap_servers=self._bootstrap_server, group_id=self._groupId,client_id=self._clientId,enable_auto_commit=True, auto_commit_ Interval_ms=5000,value_deserializer=lambdam:json.loads (M.decode (' Utf-8 '))) "" " There is no need to display theThe subscription function is called, the theme is specified when initializing the Kafkaconsumer object, and the subscription function is au
Today, read a blog, the Java multi-thread threads of collaboration, in which the author uses the program examples to illustrate the producer and consumer issues, but I and other readers found that the program more than a few times there will be a deadlock, Baidu searched the majority of the sample also has a bug, after careful study found in the problem. And conquer, feel meaningful paste out to share under
* *
@author Martin */Public
class Creator2 implements Runnable {
/**
* Thread Resources
* *
private Plate Plate;
Public Creator2 (Plate Plate) {
this.plate = Plate;
}
@Override public
Void Run () {
synchronized (plate) {
//If the number of eggs is greater than 0 at this time, wait while
(Plate.geteggnum ()) >= 5) {
try {///
This detail requires that if the thread enters a wait, the lock on it is temporarily released,/
/Otherwise the other thread cannot lo
Producer-consumer model, producer-consumer model
Introduction
The producer-consumer model is a classic multi-threaded design model that provides a good solution for multi-threaded collaboration. In
The Producer-consumer producer-consumer model we are introducing here is a well-known design pattern in multithreaded design patterns. When it comes to producer-consumer problems, most people are not unfamiliar with the classic pr
The producer producer, by definition, is the thread of production data, and the consumer consumer is the thread that uses the data. Can have more than one producer, can also have multiple consumers, when the producer and the
Producer and consumer issues in java threads, java producer
I. Concepts
The producer-consumer issue is a golden multi-thread collaboration problem. The producer is responsible for producing and storing the product in the warehouse
Java5 has added a lot of thread synchronization features, such as explicit lock, read-write lock readwritelock, conditional variable condition, etc., although these features can be implemented using the previous synchronized synchronization keyword, but their use of synchronization keyword not only manages chaos , and error prone. The following is a better solution to the problem of producer consumers by using explicit lock and conditional variable co
Producer consumer problem is one of the classic problems in the research of multithreaded process, it describes a buffer as a storehouse, the producer can put the product into the storehouse, and the consumer can take the product from the storehouse. Solutions to producer/
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.