In this demo you see how we can use Apache Camel alongside Eureka Service Discovery in order to implement a service gateway in a Spring MVC environment (Boot-less). You are able to map eureka services with custom context paths and relegate the requests come to camel, to the appropriate eureka service. So, basically you just know about camel and are able to send requests to it and in the back-end, camel relegate your request to the appropriate eureka-service and then return the response to you.
- [Framework]
Spring MVC - [Integration Framework]
Apache Camelwhich uses Spark Java for REST API - [ORM]
Hibernateunder abstraction ofSpring Data JPA - [Database]
Oracle on port 1521
In order to test this demo you should already have the followings:
-
An Oracle database connection and consequently changing
database.propertiesfor it. In addition you should updateenums/Schema.javafile with your schema name -
An
Eurekaserver starting for registry/discovery of services. In this case you can use other repository of mine namedservice-gatewayand just startconfig-server,eureka-serverandaccount-servicemodules in order. This will start an Eureka server onlocalhost:8090and registers a REST service namedaccount-serviceon it. In case you want to change the Eureka port, you should updateeureka.propertiesfile with your own configs. -
Port
8089should be open for camel REST API. You are able to configure it inapplication.propertiesfile.
You need to run this demo on a tomcat server. For the rest of the article lets assume this demo is
started on localhost:8082.
- To get all the services:
Http.GETtohttp://localhost:8082/service-gateway/services - To add a mapping for a pair of context path and eureka service:
Http.POSTtohttp://localhost:8082/service-gateway/serviceswith the following json as request body:
{
"contextPath": "accounts",
"eurekaServiceName": "account-service",
"eurekaServiceStatusEntity": {
"id": 1,
"eurekaServiceStatusType": "PUBLISHED",
"description": "published status"
},
"subSystemCategoryEntity": {
"id": 1,
"subSystemCategoryType": "ARZI",
"description": "arzi category"
}
}
After adding the mapping of accounts context path for account-service eureka service, you are able
to call camel with Http.GET on http://localhost:8089/services/accounts to get the list of accounts
comes from account-service eureka service.