简体   繁体   English

如何在springboot中提供从azure keyvault读取到Azure Service bus Jms starter的连接字符串?

[英]How to provide connection string read from azure keyvault to Azure Service bus Jms starter in springboot?

I am using azure-spring-boot-starter-servicebus-jms dependency to read messages from azure topic service bus.我正在使用 azure-spring-boot-starter-servicebus-jms 依赖项来读取来自 azure 主题服务总线的消息。 Currently the document says to provide connection-string in application properties but I need to read connection string from azure keyvault.目前文档说在应用程序属性中提供连接字符串,但我需要从 azure keyvault 读取连接字符串。 Jms lib has AzureServiceBusJMSProperties which reads connection string from application.properties..so I am getting the error “spring.jms.servicebus.connection-string should be provided”. Jms lib 有 AzureServiceBusJMSProperties,它从 application.properties 中读取连接字符串..所以我收到错误“应该提供 spring.jms.servicebus.connection-string”。 How to inject value, read from azure keyvault,into this application properties?如何将值从 azure keyvault 读取到此应用程序属性中?

link for lib code: https://github.com/Azure/azure-sdk-for-java/blob/e81850c3fcebe0bbfe65ed3e8a1c7c0c607798cf/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure/jms/AzureServiceBusJMSProperties.java链接库代码: https://github.com/Azure/azure-sdk-for-java/blob/e81850c3fcebe0bbfe65ed3e8a1c7c0c607798cf/sdk/spring/azure-spring-boot/src/main/java/com/azure/spring/autoconfigure /jms/AzureServiceBusJMSProperties.java

  • Here is the Sample Code of Data Source which reads all common properties from Application Properties这是数据源的示例代码,它从应用程序属性中读取所有公共属性
@Value("${db-user}")
String dbUser;

@Value("${db-password}")
String dbPwd;

@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
    DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
    dataSourceBuilder.username(dbUser);
    dataSourceBuilder.password(dbPwd);
    return dataSourceBuilder.build();
}
  • All the used values are injected as above using @Value -annotation所有使用的值都使用@Value -annotation 如上所述注入
@Bean
public ServletWebServerFactory servletContainer() {

    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    TomcatConnectorCustomizer tomcatConnectorCustomizer = connector -> {
        connector.setPort(port);
        connector.setScheme("https");
        connector.setSecure(true);

        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setSSLEnabled(true);
        protocol.setKeystoreType(keyStoreType);
        protocol.setKeystoreProvider(keyStoreProvider);
        protocol.setKeystoreFile(keyStorePath);
        protocol.setKeystorePass(keyStorePassword);
        protocol.setKeyAlias(keyAlias);
        protocol.setTruststoreFile(trustStorePath);
        protocol.setTruststorePass(trustStorePassword);
        protocol.setSSLVerifyClient(clientAuth);
    };

    tomcat.addConnectorCustomizers(tomcatConnectorCustomizer);
    return tomcat;
}
  • Also Check this SO for complete information and check this Github document if you are facing any issues regarding Netty Dependency.如果您遇到有关 Netty 依赖性的任何问题,还可以查看此SO以获取完整信息并查看此Github文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM