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  |  10 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
  • Andrej
    Hubert Klein Ikkink has created another example illustrating how to poll an email box with camel and groovy.
  • sparklinks

    Groovy and Grape - easiest way to send gtalk message with Apache Camel … http://twurl.nl/oubgmt


    This comment was originally posted on Twitter

  • Dave Z
    Wow, impressive Groovy example...
    This has inspired me to do some similar Groovy ESB processing. Thanks!
  • fagunbhavsar

    Groovy and Grape - easiest way to send gtalk message with Apache Camel? http://bit.ly/7WcKh


    This comment was originally posted on Twitter

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

    Go Groovy!
  • akoelewijn
    Thx, nice example. Still trying to learn real groovy programming. Currently, i'm mostly doing java with a groovy syntax.
  • James Strachan
    BTW you can use Groovy closures as filters in the routing DSL too...

    https://svn.apache.org/repos/asf/camel/trunk/co...
  • breun

    @p3t0r Wel geinig gebruik van Apache Camel hier: http://tinyurl.com/cwnjnl


    This comment was originally posted on Twitter

  • akoelewijn
    Sure, go ahead.
  • Paul King
    Hi Andrej, nice example.
    Mind if I 'borrow' it for the Groovy wiki?
    With a link back here of course.
    Paul.
  • kenu
    Thanks. It's really short.
  • orana

    Groovy and Grape - easiest way to send gtalk message with Apache Camel? http://ff.im/-1gFej


    This comment was originally posted on Twitter

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

  • 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

  • Getting started with Nexus maven repository manager
  • JEE CDI tip: Target Unreachable, identifier resolved to null
  • Absent Code attribute in method that is not native or abstract
  • Prezi presentation software needs to add visual
  • So you think it’s the iPad that’s missing features?

Categories

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

Recent Comments

  • andrej on So you think it’s the iPad that’s missing features?
  • Dave on So you think it’s the iPad that’s missing features?
  • andrej on So you think it’s the iPad that’s missing features?
  • Fernando on So you think it’s the iPad that’s missing features?
  • andrej on So you think it’s the iPad that’s missing features?

RSS Friendfeed

  • Improving the Testability of Java EE With Arquillian; 1.0.0 Alpha 1 Released March 11, 2010
    andrej koelewijn Improving the Testability of Java EE With Arquillian; 1.0.0 Alpha 1 Released - http://feeds.dzone.com/~r... 3 hours ago from Google Reader - Comment - Like […]
    FriendFeed
  • Nice set of svg demos: http://bit.ly/cLLECf No it's not flash: http://svg-wow.org/audio/animated-lyrics.svg Bring up to date browser March 11, 2010
    andrej koelewijn Nice set of svg demos: http://svg-wow.org/ No it's not flash: http://svg-wow.org/audio... Bring up to date browser 3 hours ago from Twitter - Comment - Like […]
    FriendFeed
  • SVG Wow! March 11, 2010
    andrej koelewijn SVG Wow! - http://feedproxy.google.com/~r... 3 hours ago from Google Reader - Comment - Like […]
    FriendFeed
  • Google’s Chief Economist: “Newspapers Have Never Made Much Money From News” March 10, 2010
    andrej koelewijn Google’s Chief Economist: “Newspapers Have Never Made Much Money From News” - http://techcrunch.com/2010... yesterday from Google Reader - Comment - Like […]
    FriendFeed
  • Researching differences between Mule and Oracle OSB, any chance of reusing mule code in osb... March 10, 2010
    andrej koelewijn Researching differences between Mule and Oracle OSB, any chance of reusing mule code in osb... yesterday from Twitter - Comment - Like […]
    FriendFeed
  • RT @monkchips: DHS: Smartphones to Sniff Out Suspicious Substances http://bit.ly/cq2JRD March 10, 2010
    andrej koelewijn RT @monkchips: DHS: Smartphones to Sniff Out Suspicious Substances http://www.dhs.gov/files... yesterday from Twitter - Comment - Like […]
    FriendFeed
  • Amerikanen rangschikken Rotterdams MVRDV in top 50 March 9, 2010
    andrej koelewijn Amerikanen rangschikken Rotterdams MVRDV in top 50 - http://www.idealize.nl/2010... Tuesday from Google Reader - Comment - Like […]
    FriendFeed
  • Getting started with Nexus maven repository manager March 9, 2010
    andrej koelewijn Getting started with Nexus maven repository manager - http://www.andrejkoelewijn.com/wp... Tuesday from Google Reader - Comment - Like […]
    FriendFeed
  • @eelzinga Did you add the remote repository to the correct reposutory group in nexus? http://bit.ly/a2gTmZ March 9, 2010
    andrej koelewijn @eelzinga Did you add the remote repository to the correct reposutory group in nexus? http://www.andrejkoelewijn.com/wp... Tuesday from Twitter - Comment - Like […]
    FriendFeed
  • Getting started with Nexus maven repository manager March 9, 2010
    andrej koelewijn Getting started with Nexus maven repository manager - http://www.andrejkoelewijn.com/wp... Tuesday from Andrej Koelewijn - Comment - Like […]
    FriendFeed


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