Andrej Koelewijn

  • Home
  • About
  • Publications
  • Departments
    • agile
    • architecture
    • 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  |  23 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.

  • http://twitter.com/orana orana

    Groovy and Grape – easiest way to send gtalk message with Apache Camel? http://ff.im/-1gFej
    This comment was originally posted on Twitter

  • http://okjsp.tistory.com/ kenu

    Thanks. It’s really short.

  • http://okjsp.tistory.com kenu

    Thanks. It’s really short.

  • Paul King

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

  • Paul King

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

  • http://www.andrejkoelewijn.com/ akoelewijn

    Sure, go ahead.

  • http://www.andrejkoelewijn.com/ akoelewijn

    Sure, go ahead.

  • http://twitter.com/breun breun

    @p3t0r Wel geinig gebruik van Apache Camel hier: http://tinyurl.com/cwnjnl
    This comment was originally posted on Twitter

  • http://macstrac.blogspot.com/ James Strachan

    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

  • http://macstrac.blogspot.com/ James Strachan

    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

  • http://www.andrejkoelewijn.com/ akoelewijn

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

  • http://www.andrejkoelewijn.com/ akoelewijn

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

  • http://davsclaus.blogspot.com/ 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!

  • http://davsclaus.blogspot.com/ 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!

  • Pingback: links for 2009-03-04 « Niels’ blog

  • Pingback: Groovy example: ActiveMQ broker and Apache Camel :: Andrej Koelewijn

  • http://twitter.com/fagunbhavsar fagunbhavsar

    Groovy and Grape – easiest way to send gtalk message with Apache Camel? http://bit.ly/7WcKh
    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!

  • Dave Z

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

  • http://twitter.com/sparklinks sparklinks

    Groovy and Grape – easiest way to send gtalk message with Apache Camel … http://twurl.nl/oubgmt
    This comment was originally posted on Twitter

  • http://www.andrejkoelewijn.com/ Andrej

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

  • http://www.andrejkoelewijn.com/ Andrej

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

  • http://www.usa-basketball-shoes.com usa basketball shoes

    “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

Tags

activemq agile bi camel css esb google governance grails groovy gtalk html5 internet ipad ivy J2EE java javascript jaxrs jmx jquery lean linkeddata linux maven mule noiv openoffice opensource Open Source oracle osgi oss rdbms rest scrum servicemix soa sql svg tablet web 2.0 XML xmpp yql

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • 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
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005

Meta

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

Recent Posts

  • Updating a vagrant box
  • Using littleproxy in Mule unit tests
  • Useful site to determine what html5, css3 & svg you can use
  • A Product Owner is a Project Manager
  • Using css webfonts in inkscape

Categories

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

Recent Comments

  • Pcdiggs on Software architecture, PHP and Javascript
  • Een Scrum Product Owner is een Project Leider on A Product Owner is a Project Manager
  • Using css webfonts in inkscape :: Andrej Koelewijn on Create presentations using inkscape
  • Create presentations using inkscape :: Andrej Koelewijn on Presentation: Introduction to Scrum
  • Gebhard Greiter on What is Agile?
Buzz
andrkoel: Utrecht hele dag mist, scheveningen zomerse dag... http://t.co/cDRCJHr9
4:35 PM Nov 10, 2011, comment
andrkoel: RT @stefanvdkamp: Beter filmpje van Garret McNamara in de 30 meter hoge golf. http://t.co/9abiWkYX
9:20 AM Nov 10, 2011, comment
andrkoel: Mmm, een uur voor den haag - leiden lijkt te weinig, ga mijn afspraak niet redden...
7:34 AM Nov 10, 2011, comment
andrkoel: Big Data is Useless without Science http://t.co/2I8EiLsH
6:18 AM Nov 10, 2011, comment
andrkoel: Just tried #vagrant to quickly setup virtualbox development environment. Looks good, although provisioning apache through puppet failed...
10:47 PM Nov 09, 2011, comment
 


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