Anjali Pharswan
Anjali Pharswan

Reputation: 1

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. Currently the document says to provide connection-string in application properties but I need to read connection string from 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”. How to inject value, read from azure keyvault ,into this application properties?

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

Upvotes: 0

Views: 999

Answers (2)

unamen
unamen

Reputation: 265

If you want to manually set your own connection-string. Kindly disable/exclude the autoconfiguration file that using the AzureServiceBusJMSProperties and you also need to create the bean required in that excluded file.

Take a look at Azure service bus configuration via code spring

Upvotes: 0

SaiSakethGuduru
SaiSakethGuduru

Reputation: 2439

  • 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
@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.

Upvotes: 0

Related Questions