0.5 Beta 1 bits have been posted to our Downloads page. There are 113 issues resolved in 0.5 (so far). I'm working on a revamped Getting Started guide and Release Overview for 0.5 Final, which should drop in a couple weeks. In the meantime, this is a great time to kick the tires and help us improve things for Final. Here are some useful links:
Lots and lots of stuff in this release, but I would have to say that our new visual application editor makes the biggest impact.
We've received some great feedback at JUDCon this week and we're looking forward to people trying the Beta build and giving feedback that we can fold into 0.5 Final and 0.6. So please get your hands dirty and let us know what you think!
This post provides a brief introduction to Switchyard, what it is, and how to use it to build a service-oriented application.
This post also provides a hands-on introduction to the new SwitchYard graphical editor. We’ll build an application from scratch, but our focus will be on the tools that SwitchYard provides you, and not on the business logic of our application.
(Please note, that this post was written with the "nightly" build of Switchyard 0.5 in June 2012. The eclipse based tooling introduced in this post will be released in version 0.5 of SwitchYard.)
The post is divided into 10 sections. Let’s get started in the first section with a question, actually a few questions.
Section 1: Starting with a few Questions
Just what is Switchyard? Is it another Enterprise Service Bus (ESB)? How can I use it? Better yet, why do I want to use it? And, did I mention that I’m in a hurry? Don’t waste my time - I’ll give you 15 minutes to get me the answers.
The top level page at http://www.jboss.org/SwitchYard defines SwitchYard as:
‘...a lightweight service delivery framework providing full life-cycle support for developing, deploying, and managing service-oriented applications...’
Hang on for a minute! That’s a pretty heavyweight sentence for a lightweight framework. Let’s dissect that sentence into smaller bites to see if we can better understand SwitchYard:
Section 2: What About JBoss ESB?
So far so good, but if we’re talking about a JBoss framework for SOA, aren’t we talking about JBossESB? Does SwitchYard mean that JBossESB is dead?
No, JBossESB is not dead. JBossESB is alive and well. A new update (version 4.11) scheduled for this week. The community is growing and as vibrant as ever. There’s even a beautifully written new Beginner’s Guide (http://www.packtpub.com/jboss-esb-beginners-guide/book). (Full disclosure, I’m one of the books authors.)
Well, if JBossESB is not going away, If I want to build a new SOA application starting today, should I use ESB or SwitchYard?
The answer to this question is, “it depends.”
At this point in time, SwitchYard is very much a work in progress. It’s design and implementation are evolving and will evolve significantly in the future months as it grows toward its 1.0 release. JBoss ESB is more mature, and is undergoing primarily incremental changes and improvements.
So, if you are building an SOA application that you want to go into production in the near future, you should look at JBoss ESB. Actually, if you need enterprise level support, you should really buy a subscription for the JBoss SOA Platform (http://www.redhat.com/products/jbossenterprisemiddleware/soa), which has at its core JBoss ESB.
For the longer term future, you should look at some of the ways in which SwitchYard will make some aspects of SOA application development easier.
Section 3: Making Your SOA Life Easier with SwitchYard
The primary ways in which SwitchYard differs from a traditional ESB highlight some of the ways in which SwitchYard can make SOA application services development easier:
Section 4: Visualizing SwitchYard?
It’s easy to visualize an ESB. You just think of a bus with services “plugged” into it. But what about SwitchYard. What does SwitchYard “look like?”
An ESB, and in this context, SwitchYard is an ESB, is really a means to an end. It’s a tool for creating service-oriented applications. To create a service-oriented application you look inward at your application architecture, not outward at the runtime architecture of the bus. Your concern and your focus in on the application that you’re building and not on the runtime and tooling. SwitchYard is the tooling and runtime for your service-oriented applications.
It’s a little more difficult to draw a picture of SwitchYard, as one of its main goals is to enable you to focus on what your application looks like!
The contents of a SwitchYard project however do have a different configuration than JBoss ESB project. We’ll take a look at these differences next.
Section 5: Anatomy of a SwitchYard Project Configuration
Unlike traditional ESBs, the configuration requirements imposed by SwitchYard are minimal. Let’s use JBossESB as reference point. A service-based application deployed to JBossESB requires configuration files to define the JMS topics and queues on which it depends. It also requires a “jboss-esb.xml” file to define the resource providers (such as JMS) on which the services depend, the services themselves, the gateways through which messages are “on-boarded” to the ESB and the notifiers through which messages are sent off of the ESB, and the “pipeline” of actions that perform the tasks that comprise the services. Creating and maintaining a jboss-esb.xml file for a services-based application can be a difficult and time-consuming task.
A SwitchYard application has two primary configuration files:
At first glace, this may seem like a trivial change from jboss-esb.xml to switchyard.xml. What’s the big deal, only the file name changed, right?
The major difference is that the elements defined in switchyard.xml conform to the OASIS Service Component Architecture Assembly Model Specification (http://docs.oasis-open.org/opencsa/sca-assembly/sca-assembly-spec-v1.1.html). The Service Component Architecture (SCA) model provides standards for building SOA applications.
Why was this standard selected as the lingua franca of SwitchYard configuration? What advantages does using this standard give us? There are multiple levels of advantages:
It’s also important (as we’re all lazy programmers who want to avoid error-prone manual tasks, after all) that SwitchYard provides tools to automatically populate the contents of switchyard.xml. We’ll see these tools in action in a bit.
Section 6: Services
When we talk about SwitchYard services, we're concerned with how we can create a service, and then how that service can be used (or "consumed") by other services.
How exactly do you create a SwitchYard service? Watch closely because SwitchYard makes this simple:
And that’s all folks. You’ve got a service. Yeah, SwitchYard tries to keep this simple.
Here’s an example (thanks to Keith Babo - as I’m borrowing this code from his demo):
1) Start with a POJO:
public interface OrderService {
OrderAck submitOrder(Order order);
}
2) Create an interface:
public class OrderServiceBean implements OrderService {
public OrderAck submitOrder(Order order) {
...
}
}
3) Annotate the POJO - and it’s a service!
@Service(OrderService.class)
public class OrderServiceBean implements OrderService {
public OrderAck submitOrder(Order order) {
...
}
}
Once you have a service, how do you access/consume it? Through Context Dependency Injection (CDI) in three more steps:
(1) Add an @Reference and @Inject annotation
(2) Add a field representing the consumed service
(3) Invoke methods on the injected reference
@Service(OrderService.class)
public class OrderServiceBean implements OrderService {
@Inject @Reference (1)
private InventoryService inventory; (2)
public OrderAck submitOrder(Order order) {
Item orderItem = inventory.lookupItem(order.getItemId()); (3)
…
}}
What types of services does Switchard support?
At this point, let’s switch into to a hands on mode and perform some tasks with SwitchYard.
Section 8: Getting SwitchYard
When I first started working with JBoss software, I asked a co-worker, how do I perform an installation? His response was a blank stare for a few seconds, after which he said, “You download the .zip and unzip it.”
It might sound trivial, or obvious, but the ease, and low entry cost (you can’t get cheaper than free!) with which you can get started using JBoss projects is a great feature. You can download whatever projects you want and try them out at no cost.
To get a copy of SwitchYard, the steps you have to do are:
Go to this page: http://www.jboss.org/SwitchYard/downloads - you’ll see a display similar to this:
Your download choices are:
For the purposes of this impatient discussion, we’ll use the SwitchYard AS7 Distribution.
Section 9: Running SwitchYard and the JBoss AS7 Server
The JBoss AS7 (http://www.jboss.org/as7) server is JBoss’ newest application server release. AS7 is compliant with the Java Enterprise Edition 6 specification, and is the preferred deployment platform for SwitchYard.
(Note that by the time you read this, SwitchYard 0.5 will probably be available as a download.)
To install the SwitchYard AS7 Distribution, simply select a directory where you want to run the server, and unzip the http://downloads.jboss.org/switchyard/releases/v0.4.Final/switchyard-as7-0.4.0.Final.zip file into that directory.
In this post, we’ll use the /opt/SwitchYard directory:
mkdir /opt/SwitchYard
cd /opt/SwitchYard
unzip switchyard-as7-0.4.0.Final.zip
Let’s jump right in and start up the server:
cd switchyard-as7-0.4.0.Final/bin
sh ./standalone.sh
After a very short time (Did I mention how fast JBoss AS7 is? It starts up and runs very quickly!), you’ll see logging messages that look like this that indicate the server is up and running:
23:05:13,608 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
23:05:13,718 INFO [org.jboss.as.connector] (MSC service thread 1-5) Starting JCA Subsystem (JBoss IronJacamar 1.0.3.Final)
23:05:13,775 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) Bound data source [java:jboss/datasources/ExampleDS]
23:05:14,173 INFO [org.jboss.as.deployment] (MSC service thread 1-2) Started FileSystemDeploymentService for directory /opt/local/SwitchYard/SwitchYard-as7-0.3/standalone/deployments
23:05:14,192 INFO [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.2.Final "Arc" started in 2137ms - Started 97 of 152 services (55 services are passive or on-demand)
Section 10: Creating a New SwitchYard Project From Scratch
Now that we have SwitchYard running, let’s create a new project. We’ll do this the easy way and take advantage of some new JBoss eclipse-based tooling, the SwitchYard Graphical Editor. Note that as of this writing, the editor has not been released. It will be released in SwitchYard 0.5
First, we need to install a few things:
Once all the tools are in place, we can create a new SwitchYard project. Before we do that, however, let’s think about the application that we want to build, and the steps that we have to perform.
The application exposes a simple web service implemented in a Java bean. The service accepts a string, and prefixes the world “hello” to it. That’s right, if we pass the word “world” to the service, it returns “hello world.” We’ll access the service by sending it a SOAP message. For our “client,” we’ll use soapUI (http://www.soapui.org/).
The function performed by the application is not the important thing. What’s important is how you can build it with the SwitchYard tooling, especially the new SwitchYard graphical editor.
The major steps that we’ll perform are:
OK, let’s begin!
Note: This article was originally written in July 2012. The following sections are an update to the article using the latest release (0.7) of SwitchYard as of March 2013. The UI has changed and improved a great deal since July 2012. The screenshots that are used in the following sections reflect the current (0.7) UI.
The steps that we'll follow are:
Let's take these steps one-by-one:
Create a new SwitchYard project
To create a new SwitchYard project, select File->New->Project->SwitchYard->SwitchYard Project
We can accept most of the default settings for this project, the exception being that we have to set the bean and SOAP facets:
When the new project wizard completes, we access the new SwitchYard graphical editor by double-clicking on the SwitchYard icon in the project explorer:
And the editor is opened.
The editor consists of:
Create a bean component, and in the course of doing so, create its contract (interface)
To create a new bean component, select the Bean implementation icon from the palette and drag it onto the canvas. The Bean definition dialog opens:
To create the corresponding contract (interface) click on the blue "Interface:" text and this dialog opens:
After we select "Finish" to save the definition, we see the bean component on the canvas:
Fill in the business logic of the bean and the details of the contract (interface)
At this point, we need to fill in the code for the bean and its interface:
Promote the service so that it is visible as a web service, and in the course of doing so generate the service's WSDL, and create the necessary transformations
Next, we promote the service to make it visible (right-click on the service's green icon):
We want to make the service visible as a web service, so we'll select WSDL as the interface type - and the UI will generate a WSDL for us, based on the contract (interface) that we defined earlier:
Note that we selected to not use wrapped messages, so that our transformations can access only what is inside the elements they receive.
Our service has to transform data between objects and strings, so we next have to generate transformations:
Our (Java) transformers are quite simple:
We're almost done!
Create a SOAP binding
Now, we create a SOAP binding:
Note that you can always view/edit the binding after it's created by accessing its properties:
OK. It’s time for action. Let’s deploy our application:
And fire up soapUI, we can easily create a request by accessing the deployed service’s WSDL:
http://localhost:8080/switchyard-example1/HelloService?wsdl
http://127.0.0.1:18001/switchyard-example/HelloService?wsdl
And there it is, the output from our very small SwitchYard service.
Section 11: What’s Next?
Well, that’s a brief (impatient) introduction to Switchyard, where to get it, how to install it, and how to build a service from the bottom up. What’s next? In a followup post, we’ll take an in-depth look at the services Switchyard provides by examining some of the SwitchYard quickstarts in detail.
There are a number of great demos of SwitchYard available at the SwitchYard video channel - check it out! https://community.jboss.org/wiki/SwitchYardVideoSeries
Acknowledgements
I’d like to thank Keith Babo, Tom Cunningham, Rob Cernich, and Brian Fitzpatrick for their (never impatient) review comments and suggestions on writing this post!