Skip to content

Latest commit

 

History

History
92 lines (57 loc) · 2.91 KB

README.textile

File metadata and controls

92 lines (57 loc) · 2.91 KB

Camel Module for Play! Framework

About this module

This module aim at integrating EIP pattern into the Play! Framework.

Components of this module

Installing module

  • Using conf/dependencies.yaml and adding a dependency:
play -> camel [version]
  • Using conf/application.conf and adding a module:
module.camel=${play.path}/modules/camel-[version]

Getting dependencies

You need to make sure you are able to retreive all dependencies for this module, or it won’t work.

play deps --sync

Configuring

Not much to configure, all required settings have defaults values.

List of properties user can override

Key Default Description Required
broker.connector none (ex.: tcp://localhost:61616) host:port that will be exposed by the ActiveMQ Connector Optional
broker.url vm:localhost URL used for instanciating an embedded broker Optional
camel.hazelcast none whether to start Hazelcast as component or not (default: not) Optional

Using @Inject

You can inject CamelContext into any class by using JSR-330:


@Inject
private static CamelContext context

A good place is in a Bootstrap class, a class that extends Job and has the OnApplicationStart annotation:


@OnApplicationStart
public class Bootstrap extends Job {
...
}

Making your first Route

In the previous class in which you injected CamelContext, you can then use the Camel DSL which support:

  • Java
  • Scala

RouteBuilder : Where it all begin…

I recommend you to read the architecture documentation if you need more than this basic example.

Here is a sample route you can test easily:


// Prepare the route
RouteBuilder routes = new RouteBuilder() {
	@Override
	public void configure() throws Exception {
		from("file:///Users/marcus/tmp/INBOX").id("myInbox").log("Sending to JMS").to("activemq:testQueue");
		from("activemq:testQueue").id("myFakeEMail").log("Sending Email").to("log:myLogCategory?level=INFO&showBody=true");
	}
};

The 1st route simply check for files in my INBOX directory, and then send the content to the testQueue JMS queue. The 2nd route listen for incoming messages, then send the content to a log category. The to part could have been a ftp, a smtp, or a bean (a processor in Camel terms…)

After the routes are created, you can then deploy them using the RouteBuilder class you created directly in CamelContext:


// Add them to camel-context
ctx.addRoutes(routes);

Conclusion

You now have a fully fonctionning EIP + an embedded JMS Broker right on your Play! application.

Have fun ;-), Marc