Exception thrown when sending a message with key='1' and payload='message' to topic helloworld.t
i have made sender class using kafkatemplate bean to send payload to topic
with some configuration in SenderConfiguration class .
Sender Class
@Component
public class Sender {
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Sender.class);
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send(String topic, String payload) {
LOGGER.info("sending payload='{}' to topic='{}'", payload, topic);
kafkaTemplate.send(topic, "1", payload);
}
}
, senderConfiguration class
@Configuration
public class SenderConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
// list of host:port pairs used for establishing the initial connections to the Kakfa cluster
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return props;
}
@Bean
public ProducerFactory<String, String> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
public Sender sender() {
return new Sender();
}
}
the problem is in sending not in producing
here the application.yml file properties
kafka:
bootstrap-servers: localhost:9092
topic:
helloworld: helloworld.t
and simply controller containing
@RestController
public class Controller {
protected final static String HELLOWORLD_TOPIC = "helloworld.t";
@Autowired
private Sender sender;
@RequestMapping("/send")
public String SendMessage() {
sender.send(HELLOWORLD_TOPIC, "message");
return "success";
}
}
and the exception is
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka version : 0.10.1.1
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : f10ef2720b03b247
2017-12-20 09:59:04.654 ERROR 10816 --- [nio-7060-exec-1] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='1' and payload='message' to topic helloworld.t:
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
java spring-boot apache-kafka spring-restcontroller spring-kafka
add a comment |
i have made sender class using kafkatemplate bean to send payload to topic
with some configuration in SenderConfiguration class .
Sender Class
@Component
public class Sender {
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Sender.class);
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send(String topic, String payload) {
LOGGER.info("sending payload='{}' to topic='{}'", payload, topic);
kafkaTemplate.send(topic, "1", payload);
}
}
, senderConfiguration class
@Configuration
public class SenderConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
// list of host:port pairs used for establishing the initial connections to the Kakfa cluster
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return props;
}
@Bean
public ProducerFactory<String, String> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
public Sender sender() {
return new Sender();
}
}
the problem is in sending not in producing
here the application.yml file properties
kafka:
bootstrap-servers: localhost:9092
topic:
helloworld: helloworld.t
and simply controller containing
@RestController
public class Controller {
protected final static String HELLOWORLD_TOPIC = "helloworld.t";
@Autowired
private Sender sender;
@RequestMapping("/send")
public String SendMessage() {
sender.send(HELLOWORLD_TOPIC, "message");
return "success";
}
}
and the exception is
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka version : 0.10.1.1
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : f10ef2720b03b247
2017-12-20 09:59:04.654 ERROR 10816 --- [nio-7060-exec-1] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='1' and payload='message' to topic helloworld.t:
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
java spring-boot apache-kafka spring-restcontroller spring-kafka
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
ProducerConfig
is the wrong class to look at
– cricket_007
Dec 20 '17 at 7:56
>Failed to update metadata after 60000 ms.
- often simply means the broker is not running.
– Gary Russell
Dec 20 '17 at 15:13
add a comment |
i have made sender class using kafkatemplate bean to send payload to topic
with some configuration in SenderConfiguration class .
Sender Class
@Component
public class Sender {
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Sender.class);
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send(String topic, String payload) {
LOGGER.info("sending payload='{}' to topic='{}'", payload, topic);
kafkaTemplate.send(topic, "1", payload);
}
}
, senderConfiguration class
@Configuration
public class SenderConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
// list of host:port pairs used for establishing the initial connections to the Kakfa cluster
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return props;
}
@Bean
public ProducerFactory<String, String> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
public Sender sender() {
return new Sender();
}
}
the problem is in sending not in producing
here the application.yml file properties
kafka:
bootstrap-servers: localhost:9092
topic:
helloworld: helloworld.t
and simply controller containing
@RestController
public class Controller {
protected final static String HELLOWORLD_TOPIC = "helloworld.t";
@Autowired
private Sender sender;
@RequestMapping("/send")
public String SendMessage() {
sender.send(HELLOWORLD_TOPIC, "message");
return "success";
}
}
and the exception is
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka version : 0.10.1.1
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : f10ef2720b03b247
2017-12-20 09:59:04.654 ERROR 10816 --- [nio-7060-exec-1] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='1' and payload='message' to topic helloworld.t:
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
java spring-boot apache-kafka spring-restcontroller spring-kafka
i have made sender class using kafkatemplate bean to send payload to topic
with some configuration in SenderConfiguration class .
Sender Class
@Component
public class Sender {
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Sender.class);
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send(String topic, String payload) {
LOGGER.info("sending payload='{}' to topic='{}'", payload, topic);
kafkaTemplate.send(topic, "1", payload);
}
}
, senderConfiguration class
@Configuration
public class SenderConfig {
@Value("${kafka.bootstrap-servers}")
private String bootstrapServers;
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>();
// list of host:port pairs used for establishing the initial connections to the Kakfa cluster
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
return props;
}
@Bean
public ProducerFactory<String, String> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
@Bean
public Sender sender() {
return new Sender();
}
}
the problem is in sending not in producing
here the application.yml file properties
kafka:
bootstrap-servers: localhost:9092
topic:
helloworld: helloworld.t
and simply controller containing
@RestController
public class Controller {
protected final static String HELLOWORLD_TOPIC = "helloworld.t";
@Autowired
private Sender sender;
@RequestMapping("/send")
public String SendMessage() {
sender.send(HELLOWORLD_TOPIC, "message");
return "success";
}
}
and the exception is
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka version : 0.10.1.1
2017-12-20 09:58:04.645 INFO 10816 --- [nio-7060-exec-1] o.a.kafka.common.utils.AppInfoParser : Kafka commitId : f10ef2720b03b247
2017-12-20 09:59:04.654 ERROR 10816 --- [nio-7060-exec-1] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='1' and payload='message' to topic helloworld.t:
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
java spring-boot apache-kafka spring-restcontroller spring-kafka
java spring-boot apache-kafka spring-restcontroller spring-kafka
edited Dec 20 '17 at 8:22
Shaaban Ebrahim
asked Dec 20 '17 at 7:34


Shaaban EbrahimShaaban Ebrahim
2,97311017
2,97311017
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
ProducerConfig
is the wrong class to look at
– cricket_007
Dec 20 '17 at 7:56
>Failed to update metadata after 60000 ms.
- often simply means the broker is not running.
– Gary Russell
Dec 20 '17 at 15:13
add a comment |
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
ProducerConfig
is the wrong class to look at
– cricket_007
Dec 20 '17 at 7:56
>Failed to update metadata after 60000 ms.
- often simply means the broker is not running.
– Gary Russell
Dec 20 '17 at 15:13
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
ProducerConfig
is the wrong class to look at– cricket_007
Dec 20 '17 at 7:56
ProducerConfig
is the wrong class to look at– cricket_007
Dec 20 '17 at 7:56
>
Failed to update metadata after 60000 ms.
- often simply means the broker is not running.– Gary Russell
Dec 20 '17 at 15:13
>
Failed to update metadata after 60000 ms.
- often simply means the broker is not running.– Gary Russell
Dec 20 '17 at 15:13
add a comment |
2 Answers
2
active
oldest
votes
Use the method that includes a key
kafkaTemplate.send(topic, key, payload);
Its not clear what key value you want to use, but it should evenly distribute amongst the partition count of the topic. For example, a random number within the range of the partition count.
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
add a comment |
That means your brokers are not running.
check server.log and restart broker if necessary
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47900942%2fexception-thrown-when-sending-a-message-with-key-1-and-payload-message-to-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the method that includes a key
kafkaTemplate.send(topic, key, payload);
Its not clear what key value you want to use, but it should evenly distribute amongst the partition count of the topic. For example, a random number within the range of the partition count.
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
add a comment |
Use the method that includes a key
kafkaTemplate.send(topic, key, payload);
Its not clear what key value you want to use, but it should evenly distribute amongst the partition count of the topic. For example, a random number within the range of the partition count.
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
add a comment |
Use the method that includes a key
kafkaTemplate.send(topic, key, payload);
Its not clear what key value you want to use, but it should evenly distribute amongst the partition count of the topic. For example, a random number within the range of the partition count.
Use the method that includes a key
kafkaTemplate.send(topic, key, payload);
Its not clear what key value you want to use, but it should evenly distribute amongst the partition count of the topic. For example, a random number within the range of the partition count.
answered Dec 20 '17 at 7:55
cricket_007cricket_007
83.8k1147118
83.8k1147118
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
add a comment |
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
it still throw same exception in addition the key . Exception thrown when sending a message with key='1' and payload='hhshshs' to topic helloworld.t:
– Shaaban Ebrahim
Dec 20 '17 at 8:01
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
Well, then the exception has nothing to do with the key, but this is the question that you asked. Show the rest of the stacktrace
– cricket_007
Dec 20 '17 at 8:04
add a comment |
That means your brokers are not running.
check server.log and restart broker if necessary
add a comment |
That means your brokers are not running.
check server.log and restart broker if necessary
add a comment |
That means your brokers are not running.
check server.log and restart broker if necessary
That means your brokers are not running.
check server.log and restart broker if necessary
answered Jan 2 at 22:16
SantoshSantosh
786
786
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47900942%2fexception-thrown-when-sending-a-message-with-key-1-and-payload-message-to-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You'll need to look at the internals of that ProducerFactory... Or there's a send method that includes a key, not just the topic and value
– cricket_007
Dec 20 '17 at 7:48
For example docs.spring.io/spring-kafka/api/org/springframework/kafka/core/…
– cricket_007
Dec 20 '17 at 7:49
I found KEY_SERIALIZER_CLASS_CONFIG and KEY_SERIALIZER_CLASS_DOC .but there is no relation between them and exception as i think
– Shaaban Ebrahim
Dec 20 '17 at 7:54
ProducerConfig
is the wrong class to look at– cricket_007
Dec 20 '17 at 7:56
>
Failed to update metadata after 60000 ms.
- often simply means the broker is not running.– Gary Russell
Dec 20 '17 at 15:13