我们已经编写了一个Java客户端,用于将消息发布到kafka。代码如下所示
Properties props = new Properties();
props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "202.xx.xx.xxx:9092");
props.setProperty(ProducerConfig.METADATA_FETCH_TIMEOUT_CONFIG,Integer.toString(5 * 1000));
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class.getName());
//1. create KafkaProducer
KafkaProducer producer = new KafkaProducer(props);
//2 create callback
Callback callback = new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {
System.out.println("Error while sending data");
if (e != null);
e.printStackTrace();
}
};
producer.send(record, callback);
当我们执行此代码时,我们得到以下消息和异常
ProducerConfig values:
compression.type = none
metric.reporters = []
metadata.max.age.ms = 300000
metadata.fetch.timeout.ms = 5000
acks = 1
batch.size = 16384
reconnect.backoff.ms = 10
bootstrap.servers = [202.xx.xx.xx:9092]
receive.buffer.bytes = 32768
retry.backoff.ms = 100
buffer.memory = 33554432
timeout.ms = 30000
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
retries = 0
max.request.size = 1048576
block.on.buffer.full = true
value.serializer = class org.apache.kafka.common.serialization.StringSerializer
metrics.sample.window.ms = 30000
send.buffer.bytes = 131072
max.in.flight.requests.per.connection = 5
metrics.num.samples = 2
linger.ms = 0
client.id =
Updated cluster metadata version 1 to Cluster(nodes = [Node(202.xx.xx.xx, 9092)], partitions = [])
Starting Kafka producer I/O thread.
The configuration metadata.broker.list = null was supplied but isn't a known config.
The configuration request.required.acks = null was supplied but isn't a known config.
Kafka producer started
Trying to send metadata request to node -1
Init connection to node -1 for sending metadata request in the next iteration
Initiating connection to node -1 at 202.xx.xx.xx:9092.
Trying to send metadata request to node -1
Completed connection to node -1
Trying to send metadata request to node -1
Sending metadata request ClientRequest(expectResponse=true, payload=null, request=RequestSend(header= {api_key=3,api_version=0,correlation_id=0,client_id=producer-1}, body={topics=[HelloWorld]})) to node -1
Updated cluster metadata version 2 to Cluster(nodes = [Node(0, 192.local, 9092)], partitions = [Partition(topic = HelloWorld, partition = 0, leader = 0, replicas = [0,], isr = [0,]])
Initiating connection to node 0 at 192.local:9092.
0 max latency = 219 ms, avg latency = 0.00022
1 records sent in 219 ms ms. 4.57 records per second (0.00 mb/sec).Error connecting to node 0 at 192.local:9092:
java.io.IOException: Can't resolve address: 192.local:9092
at org.apache.kafka.common.network.Selector.connect(Selector.java:138)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:417)
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:116)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:165)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:122)
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.kafka.common.network.Selector.connect(Selector.java:135)
... 5 more
Beginning shutdown of Kafka producer I/O thread, sending remaining records.
Initiating connection to node 0 at 192.local:9092.
Error connecting to node 0 at 192.local:9092:
java.io.IOException: Can't resolve address: 192.local:9092
at org.apache.kafka.common.network.Selector.connect(Selector.java:138)
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:417)
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:116)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:165)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:135)
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.kafka.common.network.Selector.connect(Selector.java:135)
... 5 more
Give up sending metadata request since no node is available
这发生在无限循环中,并且应用程序挂起…当我们检查kafka代理时,发现该主题已创建…但是我们没有收到消息…我们已经坚持了一段时间。 .. 请帮忙
我们终于解决了这个问题…我们在混合环境中运行kafka,如下文所述-
https://medium.com/@thedude_rog/running-kafka-in-a-hybrid-cloud-
environment-17a8f3cfc284
我们将host.name更改为内部IP,并将advertised.host.name更改为外部IP
我使用的是ModeShape 2.8.2和JBoss 7.1.1。ModeShape rest服务器部署为通常的web应用程序。我有个愚蠢的问题。 我可以发布一个文件-它上传到存储,一切都很好。 但是中的url是正确的,并且对url的get请求返回关于节点的详细信息。 谢谢你的帮助。祝你有个愉快的一天!
物联网有很多设备,通过这条指令可以向某个特定的物联网设备发送特定的消息内容。 请求方式: "|4|1|3|topic|message|" 参数: topic 设置订阅的topic,获取设备topic可参考教程 message 发布消息的内容 返回值: "|4|1|3|1|\r" 消息发送成功 "|4|1|3|2|\r" 消息发送失败 Arduino样例: softSerial.print("|4|
使用Spring工具套件3.6.1 Spring 4.1.1版-发行版 这是一个maven项目 它没有任何编译错误 执行mvn清洁安装时,生成成功
我有一个SpringMVC应用程序(4.1.1版本)。当我尝试在服务器上发布和运行时,我遇到了下面提到的错误。 补充资料 使用Spring工具套件3.6.1 Spring版本4.1.1-RELEASE 这是一个专业项目 它没有任何编译错误 当我进行mvn清理安装时,构建是成功的
我有ASP.NETCore C#web应用程序。我做了一些现在使用C#7.1功能的更改。我更改了项目版本,因此它可以编译和运行。但是,当我尝试发布项目时,我收到了一个错误: C# 7.0中没有“默认文本”功能。请使用语言版本7.1或更高版本。 我看到的编译命令是: 正如其他地方建议的那样,我安装了(v2.6.1),但没有任何区别。 是否有专门影响发布的 Visual Studio 设置? 更新:看
我的机器人不能发送嵌入或常规文本信息,代码执行,但没有什么是发送在不和谐的通道。我遵循了JDA维基的设置,我不知道我做错了什么。 机器人登录码