You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Blair <bl...@gmail.com> on 2011/02/14 03:43:01 UTC

Camel from the Scala command line

Due to a fault in one of the third party cloud projects we have been talking
to, we needed to produce a system that took http requests, logged what we
were called with (so we could process them later) and return a 200(ok) http
header, with the text "OK" in it. And we needed one in under 10 minutes!, as
the server that was handling the requests were going off line.

We didn't know which Uri's were going to be called on the system, so it had
to work for any of them...

Happily, setting up camel (since we already has a bunch of maven based
projects using it) and getting the route was trivial.

it looked like...

from("jetty:http://0.0.0.0:8123?matchOnUriPrefix=true").to("log:log").transform(constant("OK"));
and that was it - pure magic :)

It got me thinking that prebuilt project that we could control camel from an
interactive shell would be very useful for situations like this.

I've started experimenting with the Scala interactive shell as a way of
defining and starting / stopping routes.

Has anyone else tried anything like this? Would this be useful to anyone if
we can get it to work?

--- Blair
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-from-the-Scala-command-line-tp3383925p3383925.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel from the Scala command line

Posted by Martin Krasser <kr...@googlemail.com>.
Hi Blair,

this would be very helpful. Although I didn't use plain Camel with the 
Scala REPL yet, I was using 
https://github.com/krasserm/scalaz-camel/wiki a lot recently. Example 
(with the Scala console started from sbt inside scalaz-camel):

scala> import scalaz.camel._
import scalaz.camel._

scala> import Camel._
import Camel._

scala> implicit val router = new Router(new 
org.apache.camel.impl.DefaultCamelContext)
router: scalaz.camel.Router = scalaz.camel.Router@3d66c39

scala> router.start
Feb 14, 2011 9:01:51 AM org.apache.camel.impl.DefaultCamelContext start
INFO: Apache Camel 2.5.0 (CamelContext: camel-1) is starting
...

scala> def appnd(s:String) = (m:Message) => m.appendToBody(s) // example 
message processor
appnd: (s: String)(scalaz.camel.Message) => scalaz.camel.Message

scala> from("direct:test") { appnd("-1") >=> appnd("-2") } // example route

scala> val template = router.context.createProducerTemplate // create 
producer template
template: org.apache.camel.ProducerTemplate = 
org.apache.camel.impl.DefaultProducerTemplate@32326807

scala> template.requestBody("direct:test", "a")
res2: java.lang.Object = a-1-2

Using plain Camel with the Scala REPL should comparable easy.

Cheers,
Martin

Am 14.02.11 03:43, schrieb Blair:
> Due to a fault in one of the third party cloud projects we have been talking
> to, we needed to produce a system that took http requests, logged what we
> were called with (so we could process them later) and return a 200(ok) http
> header, with the text "OK" in it. And we needed one in under 10 minutes!, as
> the server that was handling the requests were going off line.
>
> We didn't know which Uri's were going to be called on the system, so it had
> to work for any of them...
>
> Happily, setting up camel (since we already has a bunch of maven based
> projects using it) and getting the route was trivial.
>
> it looked like...
>
> from("jetty:http://0.0.0.0:8123?matchOnUriPrefix=true").to("log:log").transform(constant("OK"));
> and that was it - pure magic :)
>
> It got me thinking that prebuilt project that we could control camel from an
> interactive shell would be very useful for situations like this.
>
> I've started experimenting with the Scala interactive shell as a way of
> defining and starting / stopping routes.
>
> Has anyone else tried anything like this? Would this be useful to anyone if
> we can get it to work?
>
> --- Blair

-- 
Martin Krasser

blog:    http://krasserm.blogspot.com
code:    http://github.com/krasserm
twitter: http://twitter.com/mrt1nz