davsclaus commented on code in PR #24320:
URL: https://github.com/apache/camel/pull/24320#discussion_r3620238172
##########
components/camel-opensearch/src/main/java/org/apache/camel/component/opensearch/OpensearchProducer.java:
##########
@@ -451,7 +458,7 @@ private void cleanup(ActionContext ctx) {
@Override
protected void doStart() throws Exception {
super.doStart();
- if (!configuration.isDisconnect()) {
+ if (!configuration.isDisconnect() && openSearchClient == null) {
Review Comment:
This guard correctly skips `startClient()` when a custom `OpenSearchClient`
is set — good.
However, `doStop()` (line 550 in the current file) is missing the same
guard. It unconditionally closes `client` if non-null, which is inconsistent
with the lifecycle pattern established here, in `process()`, and in `cleanup()`.
```suggestion
if (!configuration.isDisconnect() && openSearchClient == null) {
```
And `doStop()` should similarly be guarded:
```java
if (client != null && openSearchClient == null) {
```
##########
components/camel-opensearch/src/main/docs/opensearch-component.adoc:
##########
@@ -406,3 +406,32 @@ MsearchRequest.Builder builder = new
MsearchRequest.Builder().index("twitter").s
.body(new MultisearchBody.Builder().query(b -> b.matchAll(x ->
x)).build()).build());
List<MultiSearchResponseItem<?>> response =
template.requestBody("direct:multiSearch", builder, List.class);
----
+
+=== Custom OpenSearchClient Example
+
+DeleteIndex operation using a custom OpenSearchClient that uses AWS SDK
transport. When both restClient and openSearchClient are present in registry,
openSearchClient takes precedence over restClient.
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+SdkHttpClient httpClient = ApacheHttpClient.builder().build();
+final ObjectMapper mapper = new ObjectMapper();
+mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+OpenSearchTransport transport = new AwsSdk2Transport(
+ httpClient, host, Region.of(region),
+ AwsSdk2TransportOptions.builder()
+ .setCredentials(buildCredentialsProvider())
+ .setMapper(new JacksonJsonpMapper(mapper))
+ .build());
+OpenSearchClient customClient = new OpenSearchClient(transport);
+
+getContext().getRegistry().bind("customClient", customClient);
+
+from("direct:deleteIndex")
+
.to("opensearch://foo?operation=DeleteIndex&indexName=twitter&openSearchClient=#customClient");
+
+----
+====
Review Comment:
Missing trailing newline at end of file.
--
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]