Andrej Koelewijn

  • Home
  • About
  • Departments
    • cloud
    • java
    • mobile
    • open standards
    • oracle
    • oss
    • other
    • soa
    • software development
    • tablet
    • Uncategorized
    • web
  • Subscribe via RSS

Groovy and Grape – easiest way to send gtalk message with Apache Camel?

February 28th, 2009  |  Published in soa  |  11 Comments

Groovy 1.6 makes it really easy to quickly try out new frameworks. Dependency management build into the language allows you to write simple scripts, all required libraries will be downloaded automatically when you run it.

Here’s an example using Apache Camel. This script can simply be run from the command prompt. Groovy will compile it, download all dependencies and run it. The dependencies are specified using the @Grab annotation. Groovy uses Ivy to download these dependecies.

#!/usr/local/groovy-1.6.0/bin/groovy

import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.language.groovy.GroovyRouteBuilder;

@Grab(group='org.apache.camel', module='camel-groovy', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-xmpp', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-core', version='1.6.0')
class SampleRoute extends GroovyRouteBuilder {
  protected void configure(){
  	from("file:///tmp/jabber").
  	  to("xmpp://talk.google.com:5222/touser@gmail.com?serviceName=gmail.com&user=fromuser&password=secret");
  }
}

def camelCtx = new DefaultCamelContext()
camelCtx.addRoutes(new SampleRoute());
camelCtx.start();

The script defines a Camel Route which will look for files in the folder /tmp/jabber. Whenever it finds a new file, the file is sent to the gtalk account specified.

Before you can run this script, you need to configure an extra maven repository. The smack library used to do xmpp communication from Java isn’t included in any of the default maven repositories, so we need to add a ServiceMix repository, hosted by apache. All the other lines are copied from the default grapeConfig. Save the following document in $HOME/.groovy/grapeConfig.xml. It’s a normal ivy settings configuration file, but specifically used by Groovy.

<?xml version="1.0" encoding="utf-8"?>
<ivysettings>
  <settings defaultResolver="downloadGrapes" />
  <resolvers>
    <chain name="downloadGrapes">
      <filesystem name="cachedGrapes">
        <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml" />
        <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]" />
      </filesystem>
      <!-- todo add 'endorsed groovy extensions' resolver here -->
      <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true" />
      <ibiblio name="ibiblio" m2compatible="true" />
      <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true" />
      <ibiblio name="apache-servicemix-repository" root="http://svn.apache.org/repos/asf/servicemix/m2-repo" m2compatible="true" usepoms="true" />
    </chain>
  </resolvers>
</ivysettings>

One small script and you’re running a small ESB. Doesn’t get much simpler than this.

Share and Enjoy:
  • del.icio.us
  • Google Bookmarks
  • DZone
  • SphereIt
  • StumbleUpon
  • Technorati
  • LinkedIn
  • HackerNews
  • PDF
  • Digg
  • Facebook
  • FriendFeed
  • Posterous
  • Tumblr
  • Twitter
  • RSS

View Comments

Feed Trackback Address
  1. kenu says:

    March 1st, 2009 at 10:34 pm (#)

    Thanks. It’s really short.

  2. Paul King says:

    March 1st, 2009 at 11:18 pm (#)

    Hi Andrej, nice example.
    Mind if I ‘borrow’ it for the Groovy wiki?
    With a link back here of course.
    Paul.

  3. akoelewijn says:

    March 1st, 2009 at 11:45 pm (#)

    Sure, go ahead.

  4. James Strachan says:

    March 3rd, 2009 at 8:49 pm (#)

    BTW you can use Groovy closures as filters in the routing DSL too…

    https://svn.apache.org/repos/asf/camel/trunk/components/camel-groovy/src/test/resources/org/apache/camel/language/groovy/example/GroovyRoutes.groovy

  5. akoelewijn says:

    March 3rd, 2009 at 9:14 pm (#)

    Thx, nice example. Still trying to learn real groovy programming. Currently, i’m mostly doing java with a groovy syntax.

  6. Claus Ibsen says:

    March 4th, 2009 at 1:02 pm (#)

    Nice blog. Really shows the power and innovation by Groovy to add that @Grab annotation for prototyping and trying out frameworks.

    Go Groovy!

  7. links for 2009-03-04 « Niels’ blog says:

    March 5th, 2009 at 7:17 am (#)

    [...] Groovy and Grape – easiest way to send gtalk message with Apache Camel? :: Andrej Koelewijn (tags: eai esb camel groovy xmpp howto) [...]

  8. Groovy example: ActiveMQ broker and Apache Camel :: Andrej Koelewijn says:

    March 11th, 2009 at 2:59 pm (#)

    [...] with groovy scripting, to quickly prototype some ESB scenarios. Last week i blogged about using groovy to write files to a gtalk account using Apache Camel, the example below shows you how to start an ActiveMQ broker, which persists messages to a [...]

  9. Dave Z says:

    March 17th, 2009 at 7:32 pm (#)

    Wow, impressive Groovy example…
    This has inspired me to do some similar Groovy ESB processing. Thanks!

  10. Andrej says:

    April 2nd, 2009 at 7:26 am (#)

    Hubert Klein Ikkink has created another example illustrating how to poll an email box with camel and groovy.

  11. usa basketball shoes says:

    July 13th, 2010 at 6:27 am (#)

    “Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum! usa basketball shoes

Leave a Response

blog comments powered by Disqus

Tags

bi bpel camel cep css dsl esb esper google governance grails groovy gtalk html5 innovation internet ipad ivy java javascript jaxrs jersey jigsaw jquery linkeddata linux maven middleware mule noiv openoffice openweb oracle osgi oss plsql rdbms rest soa sql sun tablet web 2.0 xmpp yql

Archives

  • August 2010
  • June 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • Nice Java Decompiler tool: JD
  • VMware Player: The virtual machine is busy.
  • Adding a maven repository for installing features to ServiceMix
  • Upgrade Apache Camel in ServiceMix to version 2.3.0
  • A composite Rest service using Apache Camel

Categories

  • cloud
  • java
  • mobile
  • open standards
  • oracle
  • oss
  • other
  • soa
  • software development
  • tablet
  • Uncategorized
  • web

Recent Comments

  • Buddhika on Using google talk from java example
  • Anonymous on A composite Rest service using Apache Camel
  • Guest on How to find true cause of com.sun.star.uno.RuntimeException?
  • Absent Code attribute in method that is not native or abstract « Gooder Code - web development blog, php, java, asp.net, html, javascript on Absent Code attribute in method that is not native or abstract
  • Rmfume on Oracle best thing that could happen to JavaFX?
Buzz
andrkoel: RT @monkchips: James Governor's Monkchips » Day of The Dead: Web Drives Strong Demand for Java Skills http://monk.ly/d4UlND
59 minutes ago, comment
andrkoel: RT @monkchips: In which my business partner @sogrady explains Why You Should Pay Attention to Node.Js http://monk.ly/a4aGIP serverside # ...
7 hours ago, comment
andrkoel: RT @stilkov: http://bit.ly/cDdqgl - AWS Identity and Access Management — I'd hate to have to compete against Amazon's Cloud offerings
13 hours ago, comment
andrkoel: Twitter for ipad is nice, but i still think i need a tool to summarize all info, something like feedly or flipboard is the future
8:36 AM Sep 02, 2010, comment
andrkoel: Trying out the new twitter for ipad... Curious how the panels work.
8:32 AM Sep 02, 2010, comment
 


©2010 Andrej Koelewijn
Powered by WordPress using the Gridline Lite theme by Graph Paper Press.