ibeans dead simple integration
DESCRIPTION
Many web applications need integration capabilities but don't want to build an ESB solution. Typically, they want a simple solution for performing common integration tasks such as receiving and sending messages over Email, JMS or calling a Web Service. This talk will cover some options available that greatly reduce the amount of code and effort for performing these tasks without introducing new complexities or architecture considerations using new framework - iBeans.TRANSCRIPT
All contents Copyright © 2009, MuleSoft Inc.
iBeansdead-simple integration
for the web
All contents Copyright © 2009, MuleSoft Inc.
about me
• Creator of the Mule ESB Project 2003
• Founder, MuleSoft
• Creator of iBeans
• 15 years of hooking s#!t together
• Lazy
All contents Copyright © 2009, MuleSoft Inc.
agenda
• Introduction to iBeans
• The API
• Code dive
• Demo
• The future of iBeans
All contents Copyright © 2009, MuleSoft Inc.
overview
All contents Copyright © 2009, MuleSoft Inc.
goals
• Integration for the Web
• No SOA
• Minimal concepts, no TLAs
• Reuse
• Task-focused
• Cross-platform; Java, JS, Scala, JRuby
All contents Copyright © 2009, MuleSoft Inc.
application annotations
• Receive and send data
• Schedule tasks
• Create request / response services
• HTTP, JMS, DB, FTP, etc
• Use on your application objects
– POJOs, Spring beans, Struts actions, etc
All contents Copyright © 2009, MuleSoft Inc.
ibean objects• iBeans are simple objects that talk to stuff
All contents Copyright © 2009, MuleSoft Inc.
what is an ibean?
• A well-defined interface to a service
– ‘service’ - public or internal
• HTTP, JMS, FTP, JDBC, etc.
• Developers can use public iBeans
• Developers can create their own easily
All contents Copyright © 2009, MuleSoft Inc.
Application Annotations
All contents Copyright © 2009, MuleSoft Inc.
annotations: schedule
public class MyObject { @Schedule(interval=“60000”) String shoutOut() { return “Hey what’s up?”;
}
}
}
All contents Copyright © 2009, MuleSoft Inc.
annotations: schedule with cron
public class MyObject { @Schedule(cron=“0 * * * * ?”) String shoutOut() { return “Hey what’s up?”;
}
}
}
All contents Copyright © 2009, MuleSoft Inc.
public class MyObject { @Schedule(cron=“0 * * * * ?”) @Send(uri=“xmpp://${jabber.creds}@jabber.org:6666/myGroup?
groupChat=true”)
String shoutOut() { return “Hey what’s up?”;
}
}
annotations: scheduled send
All contents Copyright © 2009, MuleSoft Inc.
annotations: receive
public class MyObject { @Receive(uri=“jms://my.queue”) void onMessage(Object msg) { log(msg);
}
}
}
All contents Copyright © 2009, MuleSoft Inc.
annotations: polling receive
public class MyObject { @Schedule(cron=“0 0 12 * * ?”)
@Receive(uri=“jms://my.queue”) void onMessage(Object msg) { log(msg);
}
}
}
All contents Copyright © 2009, MuleSoft Inc.
Architecture
All contents Copyright © 2009, MuleSoft Inc.
architectureRuntime Container: Tomcat, Tcat, (Mule)Runtime Container: Tomcat, Tcat, (Mule)
iBeansiBeans
Channels: HTTP, SMTP, IMAP, REST, JDBC, JMS, XMPP, FTP
Application Annotations
Transform and BindingsScheduler
Web appsWeb apps
appswebyourconsole
iBean Objects
Formats: JSON, RSS, ATOM, XML, SOAP
All contents Copyright © 2009, MuleSoft Inc.
ibeans centralRuntime Container: Tomcat, Tcat, (Mule)Runtime Container: Tomcat, Tcat, (Mule)
iBeansiBeans
Channels: HTTP, SMTP, IMAP, WS, REST, JDBC, JMS, XMPP,
FTP, ATOM
Application Annotations
Transforms and bindings
Scheduler
Web appsWeb apps
appswebyourconsole
iBeans Centralrepository
iBean Objects
All contents Copyright © 2009, MuleSoft Inc.
iBean Objects
All contents Copyright © 2009, MuleSoft Inc.
what is an ibean?
• Encapsulates a service in a way that users don’t need to read the manual
• Use in Java, Groovy and JavaScript
– more languages to follow
• Re-usable, publish to iBeans Central
– Or a private repository
All contents Copyright © 2009, MuleSoft Inc.
using an ibean in java
public class MyObject{ @IntegrationBean
private TwitterIBean twitter; public void logTimeline() { twitter.setCredentials(“user”, “shhhh”); log(twitter.getFriendTimeline()); }}
All contents Copyright © 2009, MuleSoft Inc.
using an ibean in javascript
<script type="text/javascript”> var ibeans = new IBeansClient(); creds = ibeans.config.get(“twitter.user”, “twitter.pass”); ibeans.twitter.setCredentials(creds[0], creds[1]); ibeans.twitter.getFriendTimeline(readTweets); function readTweets(tweets, error) { //do stuff }</script>
All contents Copyright © 2009, MuleSoft Inc.
create an ibean
• A Java interface with annotated methods
• A definition of how to talk to a service
– Not the code to actually do it
All contents Copyright © 2009, MuleSoft Inc.
create an ibean
public interface MyTwitterIBean{ @Call(uri="http://twitter.com/statuses/show/{id}.json") String statusesShow(@UriParam("id") String id)
throws CallException;
}
All contents Copyright © 2009, MuleSoft Inc.
an ibean can have state
public interface MyTwitterIBean{ @State void init(@UriParam(“format”) String format);
@Call(uri="http://twitter.com/statuses/show/{id}.{format}") String statusesShow(@UriParam("id") String id) throws …;}
All contents Copyright © 2009, MuleSoft Inc.
an ibean can have defaultspublic interface MyTwitterIBean{ @UriParam(“format”) static String DEFAULT_FORMAT = “json”;
@State void init(@UriParam(“format”) String format);
@Call(uri="http://twitter.com/statuses/show/{id}.{format}") String statusesShow(@UriParam("id") String id) throws …;}
All contents Copyright © 2009, MuleSoft Inc.
Transforms & Bindings
All contents Copyright © 2009, MuleSoft Inc.
transforms
• Transformers convert one object to another
– String to a URL
– Transform XML; Xquery, XSLT
– Enrich data
All contents Copyright © 2009, MuleSoft Inc.
transforms
• Transformers are discovered not configured– Based on the current object received and the object type
required by a method parameter.
• Annotations for injecting meta data– Message headers*
– Attachments*
* not shown today
All contents Copyright © 2009, MuleSoft Inc.
transforms
public class SimpleTransformers { @Transformer URL toUrl(String string) throws MalformedURLException {
return new URL(string);
}
}
All contents Copyright © 2009, MuleSoft Inc.
bindings
• Marshal and Unmarshal Objects
– XML (JAXB)
• XML document to an Order object
– JSON (Jackson)
• JSON String to a TwitterUser object
• Supports automatic handling
All contents Copyright © 2009, MuleSoft Inc.
bindings: jaxb
public class JaxbTransformers { @Transformer Order toOrder(Document doc, JAXBContext jaxb) throws … {
Unmarshaller u = jaxb.createUnmarshaller();
return (Order) u.unmarshal(selectOne(“/env/order”, doc);
}
}
All contents Copyright © 2009, MuleSoft Inc.
bindings: jaxb
public class MyObject { @Receive(uri=“jms://my.queue”) void onMessage(@MessagePayload Order order) { log(order);
}
} Tells iBeans to transform the JMSPayload to an Order object
All contents Copyright © 2009, MuleSoft Inc.
…but wait
• How do we go from a Jms Message to an Xml Document?
• Jms Message is normalized
– TextMessage – String
– BytesMessage – byte[ ]
– ObjectMessage – Deserialized Object
– etc
All contents Copyright © 2009, MuleSoft Inc.
…and we need to add…
public class JaxbTransformers { @Transformer(sourceTypes={String.class}) Order toOrder(Document doc, JAXBContext jaxb) throws … {
Unmarshaller u = jaxb.createUnmarshaller();
return (Order) u.unmarshal(selectOne(“/env/order”, doc);
}
}
All contents Copyright © 2009, MuleSoft Inc.
transform flow
All contents Copyright © 2009, MuleSoft Inc.
an ibean can use transformerspublic interface MyTwitterIBean{ … @State void init(@UriParam(“format”) String format, @ReturnType Class retType);
@Call(uri="http://twitter.com/statuses/show/{id}.{format}")
<T> T statusesShow(@UriParam("id") String id) throws …;}
All contents Copyright © 2009, MuleSoft Inc.
an ibean can use transformerspublic interface MyTwitterIBean{ … @State void init(@UriParam(“format”) String format, @ReturnType Class retType);
@Call(uri="http://twitter.com/statuses/show/{id}.{format}")
<T> T statusesShow(@UriParam("id") String id) throws …;}
All contents Copyright © 2009, MuleSoft Inc.
coding with ibeans
• Eclipse IDE plugin
• Maven Archetypes, Run targets
• Template projects
• No Support for IntelliJ yet…
All contents Copyright © 2009, MuleSoft Inc.
Framework Support
All contents Copyright © 2009, MuleSoft Inc.
spring
<beans …> <bean name="ibeansContext” class="org.mule.ibeans.spring. IBeansContextFactoryBean"/> …</beans>
All contents Copyright © 2009, MuleSoft Inc.
guice
public class MyModule extends AbstractGuiceIBeansModule{ protected void doConfigure() throws Exception { bind(EchoService.class).asEagerSingleton(); }}
All contents Copyright © 2009, MuleSoft Inc.
coming soon
• GWT / GXT• Grails• Play Framework• JSF• Struts 2 (may already work)
All contents Copyright © 2009, MuleSoft Inc.
other things
• Support for JavaScript and AJAX
• iBeans has a Groovy shell
– Execute scripts interactively or command-line
• iBeans Console
– Configure your iBeans instance
– Browse and Download from iBeans Central
All contents Copyright © 2009, MuleSoft Inc.
possibilities
• Great for runtime containers
– Cloud containers (App Engine)
– Wikis: Confluence, Xwiki
• DSLs (Scala?)
• Mobile applications (JavaScript)
• Widgets (Google Gadgets / Wave)
All contents Copyright © 2009, MuleSoft Inc.
whats next for ibeans
• Web Services support (JAX-RS/WS)
• Support for scripting in the console
• Centralized configuration
• Mule 3.0 will be able to host iBeans
• Better JavaScript support
All contents Copyright © 2009, MuleSoft Inc.
…and after that
• Support for other languages: Scala, Ruby, Clojure, etc
• Become the WCF for the JVM?
All contents Copyright © 2009, MuleSoft Inc.
thanks
• web: http://mulesoft.org/ibeans
• blog: http://blog.rossmason.com
• twitter: @rossmason