3

I'm developing a new application which is Spring Boot with camel. I am exposing REST endpoints as part of this application.

I'm little confused to choose between these two options:

  1. Spring Rest Controller --> Spring service with producer template to call camel routes --> Camel routes for EIP
  2. Camel Rest DSL --> Camel routes for EIP

Can you please help me to choose better option?

Maik
  • 3,419
  • 1
  • 23
  • 34
Rupesh Chavan
  • 31
  • 1
  • 2

1 Answers1

4

This is your call which should you want to implement, But as you are integrating camel in spring boot so you can take advantage of REST DSL camel components and bind that flow with other components of Apache Camel, it will reduce your additional work in spring boot app to send and receive data in your other camels routes. Here is a sample CRUD rest operations using REST DSL of apache camel component.

         rest("/users").description("User REST service")
                    .consumes("application/json")
                    .produces("application/json")
    
                    .get().description("Find all users").outType(User[].class)
                    .responseMessage().code(200).message("All users successfully returned").endResponseMessage()
                    .route()
                    .to("bean:userService?method=findUsers")
                    .endRest()
    
                    .get("/{id}").description("Find user by ID")
                    .outType(User.class)
                    .param().name("id").type(RestParamType.path).description("The ID of the user").dataType("integer").endParam()
                    .responseMessage().code(200).message("User successfully returned").endResponseMessage()
                    .route()
                    .to("bean:userService?method=findUser(${header.id})")
                    .endRest()
    
                    .post().description("Create a user").type(User.class)
                    .param().name("body").type(RestParamType.body).description("The user to create").endParam()
                    .responseMessage().code(204).message("User successfully created").endResponseMessage()
                    .to("bean:userService?method=create")
    }

You can check the fully above sample app of spring boot and camel rest dsl from here

Arjun Sunil Kumar
  • 1,781
  • 3
  • 28
  • 46
Bhushan Uniyal
  • 5,575
  • 2
  • 22
  • 45
  • Thanks for your response. Can you please help me understand why you have not chosen option 1 ? Spring Rest Controller with producer template calling to other camel routes. – Rupesh Chavan Sep 05 '19 at 17:45
  • Hi @RupeshChavan, As I have mentioned you are using camel in your spring-boot project, and camel rest DSL is aware of other components of the camel so here you can directly bind camel rest component with other components of a camel without using producer as a middleware(client) b/w spring rest and other camel routes in your project. Also, you can take benefit of other ERP patterns with camel rest DSL, no need to implement your own or third-party library for a task like retry policy, etc. – Bhushan Uniyal Sep 06 '19 at 03:43
  • Thanks for the answer Bhushan. But do you mean if I have both Camel REST consumer and normal spring @RestController within a same project, they will not work together? Please have a look here https://stackoverflow.com/questions/63090630/spring-boot-2-x-with-camel-2-25-spring-specific-endpoints-not-working . Any thoughts on this? – Abhishek Chatterjee Jul 25 '20 at 16:22
  • @AbhishekChatterjee I have answered your question, let me know if you still face the issue. – Bhushan Uniyal Jul 27 '20 at 04:20