codeconsole opened a new pull request, #15716:
URL: https://github.com/apache/grails-core/pull/15716

   ## What
   
   Adds a `MongoClientSettingsBuilderCustomizer` extension point to GORM for 
MongoDB. Any beans of this type in the application context are applied, in 
order, to the `MongoClientSettings.Builder` of the default connection source 
before the `MongoClient` is created.
   
   ## Why
   
   There is currently no supported way to customize `MongoClientSettings` for 
things that have no `grails.mongodb.*` configuration equivalent — most notably 
registering a driver `com.mongodb.event.CommandListener` for metrics/tracing 
(e.g. Micrometer's `MongoMetricsCommandListener`), but also programmatic 
connection-pool tuning, read/write concerns, etc. Today that requires replacing 
the datastore wiring.
   
   Mirrors Spring Boot's `MongoClientSettingsBuilderCustomizer` of the same 
name, giving GORM-MongoDB users the same ergonomics.
   
   ## How
   
   - New functional interface 
`org.grails.datastore.mapping.mongo.connections.MongoClientSettingsBuilderCustomizer`.
   - `MongoConnectionSourceFactory` gains an `@Autowired(required = false) 
List<MongoClientSettingsBuilderCustomizer>` applied in `create()` just before 
`MongoClients.create(...)`. The factory is already registered with 
`bean.autowire = true` in `MongoDbDataStoreSpringInitializer`, so customizer 
beans are injected automatically. No behavior change when none are defined.
   
   ## Example
   
   ```groovy
   @Bean
   MongoClientSettingsBuilderCustomizer mongoMetrics(MeterRegistry registry) {
       return { builder -> builder.addCommandListener(new 
MongoMetricsCommandListener(registry)) }
   }
   ```
   
   ## Tests
   
   Added to `MongoConnectionSourceFactorySpec`:
   - a registered customizer is applied, and its command listener lands in the 
built settings
   - multiple customizers run in registration order


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to