Skip to content

Conversation

@pkalsi97
Copy link
Contributor

Description

This PR adds a feature to the camel cmd send command to support sending messages directly to infrastructure services (like NATS, Kafka, Redis, etc.) that are started with camel infra run and updated docs.

Previously, users had to manually specify server connection details, but now the command automatically reads connection information from JSON files created by infrastructure services.

How it works:

  1. When --infra option is specified, we locate the corresponding infra service JSON file.
  2. Read connection details form the JSON file.
  3. If endpoint is specified, construct the full endpoint URI
  4. Use existing message sending mechanism to send the message to the infrastructure service
  5. Handle cases where infrastructure services don't exist with appropriate error messages

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

@Croway
Copy link
Contributor

Croway commented Jan 12, 2026

Hi @pkalsi97 thanks for the PR, this is really interesting. By any chance did you test all the infrastructure? Some time ago I did an alignment of the infra properties (the key you can find in the json), with the component's properties, therefore, the mapping should work automatically, it should be safe to use jsons properties as key/values in the command. But I am not 100% sure it will work for all the usecases.

@davsclaus
Copy link
Contributor

You need to use camel-catalog it has an API for building endpoint URIs with

uri = catalog.asEndpointUri("netty-http", map, true);

Where map is a map with key/value pairs.

This will build the uri correct according to the given component.

@pkalsi97
Copy link
Contributor Author

Hey ! @Croway @davsclaus

First of all apologies, i could have tackled this issue better by first discussing the approach and solution in the issue itself before lodging the PR. I got way to excited haha. Thank a lot for your inputs i'll incorporate these in the followup.

Regarding the --infra option coverage, this got way to overlooked in the PR. I am fairly determined to cover all services, what testing approach is expected? Will Unit test (Mock the JSON for each service -> Verify the generated endpoint URI) will that be sufficient?

@Croway
Copy link
Contributor

Croway commented Jan 13, 2026

@pkalsi97 no worries! moreover, I like the idea

yeah, mocking the JSON sounds good, this way we won't have to to download all the images on the CI.

We have to make sure that all the properties in the test-infra services like https://github.com/apache/camel/blob/main/test-infra/camel-test-infra-kafka/src/main/java/org/apache/camel/test/infra/kafka/services/KafkaInfraService.java are either supported by the component as is (brokers in this case), or somehow handled, in this case getBootstrapServers is not a supported property by the component. I deprecated some of those in the past, but as you can see from the Kafka, I didn't deprecate all of them :), brokers and getBootstrapServers contain the same value at the moment.

@davsclaus
Copy link
Contributor

We can remove the deprecated options so this tool wont see "bad" options.
Then just add a note in the 4.18 upgrade guide.
Its okay, as this feature is powerful if we can get this to work correctly

@pkalsi97
Copy link
Contributor Author

pkalsi97 commented Jan 14, 2026

@Croway and @davsclaus Thanks a lot for the inputs.

I have implemented some refinements based on the feedback

  1. Now using catalog.asEndpointUri(scheme, properties, true) as suggested to build endpoint URIs.
  2. hardcoding a servers property is removed and now we uses service-specific property mappings for components requiring special handling
  3. Adds a unit test. All infra services are covered. tests are built against the actual *InfraService interface method names from test-infra modules

@pkalsi97 pkalsi97 requested a review from Croway January 14, 2026 07:27
@pkalsi97
Copy link
Contributor Author

pkalsi97 commented Jan 14, 2026

After a bit more digging it looks like not all cases in the test are setup correctly, i'll work on fixing it. I should have manually run every infra to validate my test cases with the actual. In some infra services turn out the test is validating if the properties exist but did not validate that the Camel component actually accepts those properties.

@davsclaus
Copy link
Contributor

How is it going here ?

@pkalsi97
Copy link
Contributor Author

@davsclaus Hey! its going great @Croway filled me on the right approach, i am working on it and will try to push a better implementation shortly.

@pkalsi97 pkalsi97 marked this pull request as draft January 20, 2026 13:40
@pkalsi97 pkalsi97 marked this pull request as ready for review January 21, 2026 06:50
@pkalsi97
Copy link
Contributor Author

@Croway I have made a lot of changes based on your suggestion.

I still don't think the work is complete as i am yet to manually test all infra against the command. Please review the current implementation and let me know if i am going in the right direction.

@pkalsi97 pkalsi97 requested a review from Croway January 21, 2026 06:53
@Croway
Copy link
Contributor

Croway commented Jan 21, 2026

Hi @pkalsi97 almost there! I left a couple of comments, thanks

@pkalsi97 pkalsi97 requested a review from Croway January 22, 2026 05:55
@pkalsi97
Copy link
Contributor Author

@Croway Thanks! i have removed the workarounds.


private String buildPathBasedEndpoint(String path, JsonObject connectionDetails) {

Object endpointUri = connectionDetails.get("endpointUri");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this method to handle infra like FTP, SMB, ZooKeeper etc where the connection details (host:port) and the target resource file path are fused into a single URI eg ftp://localhost:2121/myDir

If a user tries to override the target path, i came to an understanding that we would have no clean way to retain the host/port, we would loose the connection. This method safely appends the user's requested path and ensures we can switch targets dynamically without loosing the correct infra connection settings.

private Map<String, String> buildBeanProperties(JsonObject connectionDetails) {
Map<String, String> properties = new LinkedHashMap<>();

Object beanProps = connectionDetails.get("beanProperties");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was specially added to support Postgres and OpenLDAP, at least from my understanding the endpoint URI specifically refers to a named bean and since these beans aren't part of the component's schema they would be filtered out by the catalog logic.

buildBeanProperties method bridges that gap by extracting these bean definitions from the infra JSON and passing them to the Camel Main instance, ensuring the components have the dependencies they need to run.

@Croway
Copy link
Contributor

Croway commented Jan 22, 2026

Thanks @pkalsi97, I left few more comments, if the special handling for these properties are really needed (and it is not a workaround), I think we can merge as is

@github-actions github-actions bot removed the catalog label Jan 23, 2026
@pkalsi97
Copy link
Contributor Author

@Croway Thanks for the inputs and pointing out the flaws in implementations, i really picked up this issues hoping it would be a simple implementation but turn out this involved developing an understanding about all the supported infra.

If you have better suggestions regarding anything please let me know. i would be more than happy to implement or improve the current implementation.

@Croway
Copy link
Contributor

Croway commented Jan 23, 2026

@pkalsi97 looking good, I am going to merge it as soon as the CI is green. Thank you!

@davsclaus
Copy link
Contributor

Great work.

The doc says Camel 4.17 but this will make it into 4.18

@Croway Croway merged commit cb315d5 into apache:main Jan 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants