Using Multiple Spring Pulsar Clients in one application. #621
Replies: 1 comment 1 reply
-
Hello again @chaitanya-guttula-collibra , Great question. The Spring Boot autoconfiguration configures exactly 1 of each bean. This is how Spring Boot autoconfigures every technology - it does 1 set of the required components really well. It stops there though due to complexity and if you need 2 of anything, it is typically up to you to configure the 2nd set. Here is an example of needing 2 datasources: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.data-access.configure-two-datasources Option 1: Manually configure another client (and set of beans that use it)This means that you will have to configure in your 2nd client. Let's take a look at the autoconfigured PulsarClient bean If you provide the following 2 PC beans: @Bean
@Primary
PulsarClient pulsarClient1(PulsarClientFactory clientFactory) throws PulsarClientException {
return clientFactory.createClient();
}
@Bean
PulsarClient pulsarClient2() throws PulsarClientException {
return PulsarClient.builder()....
} The 1st one (marked as The 2nd one will be ignored by other components but you can look it up from the app context. If you wanted to use a PulsarTemplate for that client you will need to configure another PulsarTemplate and therefore the PulsarProducerFactory that it requires. It gets messy quick. Option 2: Use child application contexts.In this case you would configure a child app context that AC another set of Spring Pulsar. This gets complicated though. Spring Cloud Stream and Spring Cloud Loadbalancer use this technique themselves. I will take a deeper look and see if I can recommend something a bit softer than the 2 above options. |
Beta Was this translation helpful? Give feedback.
-
What is the best way to use spring-pulsar in an application, where different modules in the same application needs to connect to pulsar using different authentication credentials? Since, authentication is at the client
spring.pulsar.client.authentication
level I would assume that we would need separate pulsar client for each module but spring-pulsar does not seem to support it. Could you please help me on what would be the best way to handle this use-case. Please let me know if more info is needed.Beta Was this translation helpful? Give feedback.
All reactions