3
votes

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?

1

1 Answers

3
votes

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