JavaSwing简单发送/接收kafka数据,并打包成exe(5)

JavaSwing简单发送/接收kafka数据,并打包成exe(5):新增SSL验证

前几篇博文已经完成swing发送/接收kafka数据,新增一点内容就是开启SSL验证,如何生成SSL证书参考博文:

https://blog.csdn.net/shenyue_sam/article/details/77175734

如何搭建kafka环境详见:https://blog.csdn.net/rico_zhou/article/details/79866076

https://blog.csdn.net/rico_zhou/article/details/80332590

首先代码中新建一个类用以选择SSL证书文件


效果


在发送和接收的实现类中添加代码,验证SSL

......

Properties configProperties = new Properties();
		configProperties.put("group.id", kafkaMsg.getGroupId());
		configProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaMsg.getIpPort());
		configProperties.put("key.serializer", StringSerializer.class);
		configProperties.put("value.serializer", JsonSerializer.class);

		if (kafkaMsg.isOpenSSL()) {
			System.out.println(kafkaMsg.getSslp());
			// 添加ssl认证
			configProperties.put("security.protocol", "SSL");

			configProperties.put("ssl.truststore.location", kafkaMsg.getSslp().getTruststoreLocation());

			configProperties.put("ssl.truststore.password", kafkaMsg.getSslp().getTruststorePwd());

			configProperties.put("ssl.keystore.location", kafkaMsg.getSslp().getKeystoreLocation());

			configProperties.put("ssl.keystore.password", kafkaMsg.getSslp().getKeystorePwd());

			configProperties.put("ssl.key.password", kafkaMsg.getSslp().getKeyPwd());
		}

		KafkaProducer producer = new KafkaProducer(configProperties);

......

最终效果图


启动kafka,发送数据,接收数据,成功!


github:https://github.com/ricozhou/msgkafka2.0

欢迎交流学习!

阅读更多
文章标签: kafka swing java SSL
个人分类: kafka java Windows SSL
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭