ibeans dead simple integration

47
All contents Copyright © 2009, MuleSoft Inc. iBeans dead-simple integration for the web

Upload: ross-mason

Post on 29-Jun-2015

2.098 views

Category:

Technology


1 download

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

Page 1: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

iBeansdead-simple integration

for the web

Page 2: Ibeans Dead Simple Integration

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

Page 3: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

agenda

• Introduction to iBeans

• The API

• Code dive

• Demo

• The future of iBeans

Page 4: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

overview

Page 5: Ibeans Dead Simple Integration

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

Page 6: Ibeans Dead Simple Integration

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

Page 7: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

ibean objects• iBeans are simple objects that talk to stuff

Page 8: Ibeans Dead Simple Integration

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

Page 9: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

Application Annotations

Page 10: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

annotations: schedule

public class MyObject { @Schedule(interval=“60000”) String shoutOut() { return “Hey what’s up?”;

}

}

}

Page 11: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

annotations: schedule with cron

public class MyObject { @Schedule(cron=“0 * * * * ?”) String shoutOut() { return “Hey what’s up?”;

}

}

}

Page 12: Ibeans Dead Simple Integration

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

Page 13: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

annotations: receive

public class MyObject { @Receive(uri=“jms://my.queue”) void onMessage(Object msg) { log(msg);

}

}

}

Page 14: Ibeans Dead Simple Integration

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);

}

}

}

Page 15: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

Architecture

Page 16: Ibeans Dead Simple Integration

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

Page 17: Ibeans Dead Simple Integration

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

Page 18: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

iBean Objects

Page 19: Ibeans Dead Simple Integration

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

Page 20: Ibeans Dead Simple Integration

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()); }}

Page 21: Ibeans Dead Simple Integration

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>

Page 22: Ibeans Dead Simple Integration

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

Page 23: Ibeans Dead Simple Integration

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;

}

Page 24: Ibeans Dead Simple Integration

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 …;}

Page 25: Ibeans Dead Simple Integration

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 …;}

Page 26: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

Transforms & Bindings

Page 27: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

transforms

• Transformers convert one object to another

– String to a URL

– Transform XML; Xquery, XSLT

– Enrich data

Page 28: Ibeans Dead Simple Integration

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

Page 29: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

transforms

public class SimpleTransformers { @Transformer URL toUrl(String string) throws MalformedURLException {

return new URL(string);

}

}

Page 30: Ibeans Dead Simple Integration

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

Page 31: Ibeans Dead Simple Integration

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);

}

}

Page 32: Ibeans Dead Simple Integration

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

Page 33: Ibeans Dead Simple Integration

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

Page 34: Ibeans Dead Simple Integration

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);

}

}

Page 35: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

transform flow

Page 36: Ibeans Dead Simple Integration

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 …;}

Page 37: Ibeans Dead Simple Integration

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 …;}

Page 38: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

coding with ibeans

• Eclipse IDE plugin

• Maven Archetypes, Run targets

• Template projects

• No Support for IntelliJ yet…

Page 39: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

Framework Support

Page 40: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

spring

<beans …> <bean name="ibeansContext” class="org.mule.ibeans.spring. IBeansContextFactoryBean"/> …</beans>

Page 41: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

guice

public class MyModule extends AbstractGuiceIBeansModule{ protected void doConfigure() throws Exception { bind(EchoService.class).asEagerSingleton(); }}

Page 42: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

coming soon

• GWT / GXT• Grails• Play Framework• JSF• Struts 2 (may already work)

Page 43: Ibeans Dead Simple Integration

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

Page 44: Ibeans Dead Simple Integration

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)

Page 45: Ibeans Dead Simple Integration

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

Page 46: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

…and after that

• Support for other languages: Scala, Ruby, Clojure, etc

• Become the WCF for the JVM?

Page 47: Ibeans Dead Simple Integration

All contents Copyright © 2009, MuleSoft Inc.

thanks

• web: http://mulesoft.org/ibeans

• blog: http://blog.rossmason.com

• twitter: @rossmason