https://github.com/manosbatsis/spring-bactrian
Effortless Spring-based abstraction of Apache Camel endpoints.
https://github.com/manosbatsis/spring-bactrian
Last synced: 2 months ago
JSON representation
Effortless Spring-based abstraction of Apache Camel endpoints.
- Host: GitHub
- URL: https://github.com/manosbatsis/spring-bactrian
- Owner: manosbatsis
- License: lgpl-3.0
- Created: 2017-04-26T13:22:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-02T00:35:23.000Z (over 8 years ago)
- Last Synced: 2025-05-19T03:41:11.175Z (5 months ago)
- Language: Java
- Size: 69.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Spring Bactrian
[](https://travis-ci.org/manosbatsis/spring-bactrian)
Effortless Spring (Integration) abstractions for your Apache Camel endpoints. The project name refers to the [Bactrian camel](https://en.wikipedia.org/wiki/Bactrian_camel) (Camelus bactrianus).
- [What?](#what)
- [Why?](#why)
- [Examples](#examples)
- [Install](#install)
- [Spring Service](#spring-service)
- [Spring Integration Outbound Gateway](#spring-integration-outbound-gateway)
- [Auto mode](#auto-mode)
- [Manual mode](#manual-mode)
- [Sample Geocoder App](#sample-geocoder-app)
- [Checkout and Build](#checkout-and-build)
- [Project Structure](#project-structure)
- [Work in Progress](#work-in-progress)## What?
Minimise the effort required for abstracting Camel endpoints under regular
Spring beans or Spring Integration EIPs down to creating an interface. This should feel familiar if, for
example, you are used to using a simple interface to create a Spting Repository or other component. Bactrian
provides the same convenience, only providing you with a Spring service-like bean or Spring Integration component instead.## Why?
I was asked to provide a code sample using geocoder, Camel and Spring Integration. Since I had no real experience with any of it,
trying to integrate a bit helped me learn a few things.## Examples
Some examples are provided bellow. See also the samples geocoder app.
### Install
Add the Sonatype snapshots repo to your pom:
```xml
sonatypeSnapshots
Sonatype Snapshots
false
true
https://oss.sonatype.org/content/repositories/snapshots
```
Add Spring Bactrian as a dependency:
```xml
com.restdude
spring-bactrian
0.0.1-SNAPSHOT
```
### Spring Service
The interface bellow creates a Spring Component that abstracts a `direct:geocoder` Camel route behind a simple
Java method call (`CamelService#invoke()`).```java
/**
* A sample interface used to generate Spring Service bean for
* simplified access to a Camel {@link Endpoint} and the Geocoder component
*
*/
@CamelProxyMapping(value = "addressLookupService", mapping = "direct:geocode")
public interface AddressLookupService extends CamelService {
// no need to put anything here, clients just use the super interface method
}```
### Spring Integration Outbound Gateway
#### Auto mode
Just use `CamelProxyMessagingGateway`
#### Manual mode
If you are going manual you probably want to check the complete example in the spring-bactrian-sample-geocoder module.
Create an SI messaging gateway:
```java
@MessagingGateway(name = "entryGateway", defaultRequestChannel = CHANNEL_REQUEST)
public interface GeocoderMessagingGatewayService {Message lookup(Message message);
}
```Add a backing CamelProxy-based gateway:
```java
@Bean
@ServiceActivator(inputChannel = CHANNEL_INVOCATION)
public MessageHandler geocoderOutboundGateway() {
CamelProxyOutboundGateway gw = new CamelProxyOutboundGateway();
gw.setOutputChannelName(CHANNEL_RESPONSE);
// camel route
gw.setMapping("direct:geocode");
return gw;
}
```### Sample Geocoder App
#### Checkout and Build
*Requires: Java 8 (OpenJDK is just fine), Apache Maven 3.3.9.*
The `spring-bactrian-sample-geocoder` module contains a Spring-Boot app with the examples a nd some integration tests.
If you want to have a look go ahead andclone the project:```
git clone https://github.com/manosbatsis/spring-bactrian.git
```Navigate to the project dir:
```
cd spring-bactrian/
```Builting will compile, package, run tests and install in your local Maven repo:
```
mvn clean install
```#### Project Structure
The project follows a typicall Maven structure. Here's a quick overview sample app directory structuree:
```
spring-bactrian: The root folder, i.e. the POM module
├── spring-bactrian: The main artifact module
└── spring-bactrian-sample-geocoder: The geocoder sample app
├── src
│ ├── main/
│ │ ├── java
│ │ │ └── com
│ │ │ └── restdude
│ │ │ └── spring
│ │ │ └── bactrian
│ │ │ └── test
│ │ │ └── geocoder
│ │ │ ├── config: Configuration classes
│ │ │ └── samples
│ │ │ ├── si: Spring Integration sample classes
│ │ │ └── spring: Plain Spring samples
│ │ └── resources
│ │ └── application.properties: Application config (mostly logging levels)
│ └── test: (Integration) Test classes
```## Work in Progress
This is currently just a POC using CamelProxy to integrate with a Camel endpoint URI or route id. At the moment
generation only covers regular Spring service and Spring Integration outbound gateway components.Submission of bug reports or other issues is welcome.
TODO List
- Make this more solid and documented (generic types, tests with sync/async...)
- Add support for multiple (i.e. method-level) endpoint mapping annotations per interface via javaassist
- Add more alternatives for component generation (VS CamelProxy):
- Runtime-created bean classes for accessing "local" endpoints using regular Java API (message template or DSL retc) via javaassist/bytebuddy
- Refactore to backing plugins to allow third party/custom implementations e.g. meta-annotations and impl on top of byte buddy, AMQP or whatever
- Enhance and document support for mappers, converters, conversion service, errorh handling etc.
- Provide coverage of more EIPs