java - 使用 Spring 为 RabbitMQ 配置创建 SSLContext
问题描述
我需要创建并设置一个 SSLContext 以使用 Spring 框架连接到 RabbitMQ 队列。我使用@RabbitListener 注释并且没有SSLContext,通过将主机名、端口、用户名和密码设置到application.properties 文件中,所有的事情都完美无缺。
但是如何手动设置 SSLContext?application.properties 需要一个 JKS,但我不能使用它。我看到了一些配置bean,但是我在网上找到的根本不清楚。
如何在 Spring 框架上手动/以编程方式(精确地 SSLContext)配置 RabbitMQ?
解决方案
创建一个扩展RabbitConnectionFactoryBean
和覆盖的类createSSLContext()
。
/**
* Override this method to create and/or configure the {@link SSLContext} used
* by the {@link ConnectionFactory}.
* @return The {@link SSLContext}.
* @throws NoSuchAlgorithmException if the algorithm is not available.
* @since 1.4.4
*/
protected SSLContext createSSLContext() throws NoSuchAlgorithmException {
return SSLContext.getInstance(this.sslAlgorithm);
}
然后声明一个CachingConnectionFactory
使用工厂bean创建的rabbit连接工厂的bean。
推荐阅读
- python - Jupyter Notebook:ModuleNotFoundError:没有名为“matplotlib.pylot”的模块
- python - 在python中调用数据库时如何说高度是否重复第一个打印重量较小的行?
- python - jupyter notebook 中的“模块”对象不是可调用错误
- python - Python:硒:find_elements_by_xpath 最大 10
- r - 如何找到多个序列的所有最长公共子序列?
- javascript - JavaScript canvas使用函数一一画圈
- javascript - 在页面加载时显示地图
- unit-testing - 如何对一个方法进行单元测试,它只是在junit中初始化一个变量
- python - 使用 Python 字典时出现“ValueError:无法将字符串转换为浮点数:”
- interpolation - Modelica 模块中的多维表