Exploring the SwitchYard 2.0.0.Alpha2 Quickstarts
Exploring the SwitchYard 2.0.0.Alpha2 Quickstarts
Join the DZone community and get the full member experience.Join For Free
How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.
In one of my last posts I explained how you get started with SwitchYard on WildFly 8.1. In the meantime the project was busy and released another Alpha2. A very good opportunity to explore the quickstarts here and refresh your memory about it. Beside the version change, you can still use the earlier blog to setup you local WildFly 8 server with latest Switchyard. As with all frameworks there is plenty of stuff to explore and a prerequisite for doing this is to have a working development environment to make this easier.
Setting up JBoss Developer Studio
java -jar jbdevstudio-product-eap-universal-7.1.1.GA-v20140314-2145-B688.jar
will work. A simply 9 step installer will guide you through the steps necessary. Make sure to select the suitable JDK installation. JBDS works and has been tested with Java SE 6.x and 7.x. If you like to, install the complete EAP but it's not a requirement for this little how-to. A basic setup without EAP requires roughly 400 MB disc space and shouldn't take longer than a couple of minutes. If you're done with that part launch the IDE and go on and configure the tooling. We need the JBoss Tools Integration Stack (JBTIS). Configure them by visiting "Help -> Install New Software" and add a new Update Site with the "Add" button. Call it SY-Development and point it to: "http://download.jboss.org/jbosstools/updates/development/kepler/integration-stack/"
Wait for the list to refresh and expand the JBoss Integration and SOA Development and select all three SwitchYard entries. Click your way through the wizards and you're ready for a re-start.
|SY Tooling 2.0.0|
Please make sure to disable Honour all XML schema locations in preferences, XML→XML Files→Validation after installation. This will prevent erroneous XML validation errors from appearing on switchyard.xml files.
|Preventing erroneous XML validation|
That's it for sure. Go ahead and import the bean-service example from the earlier blog-post (Import -> Maven -> Existing Maven Projects)
General Information about SwitchYard Projects
Lets find out more about the general SwitchYard project layout before we dive into the bean-service example. A SwitchYard project is a Maven based project with the following characteristics:
- a switchyard.xml file in the project's META-INF folder
- one or more SwitchYard runtime dependencies declared in the pom.xml file
- org.switchyard:switchyard-plugin mojo configured in the pom.xml file
The Bean-Service example is one of the more simpler ones to get a first impression about SY. All of the example applications in the Quickstarts repository are included in quickstarts/ directory of your installation and also available on GitHub. The bean-service quickstart demonstrates the usage of the bean component. The scenario is easy: An OrderService, which is provided through the OrderServiceBean, and an InventoryService which is provided through the InventoryServiceBean implementation take care of orders. Orders are submitted through the OrderService.submitOrder, and the OrderService then looks up items in the InventoryService to see if they are in stock and the order can be processed. Up to here it is basically a simple CDI based Java EE application. In this application the simple process is invoked through a SOAP gateway binding (Which is indicated by the little envelope).
|Bean Service Quickstart Overview|
Let's dive into the implementation a bit. Looking at the OrderServiceBean reveals some more details. It is the implementation of the OrderService interface which defines the operations. The OrderServiceBean is just a bean class few extra CDI annotations. Most notably is the
The @Service annotation allows the SwitchYard CDI Extension to discover your bean at runtime and register it as a service. Every bean service must have an @Service annotation with a value identifying the service interface for the service. In addition to providing a service in SwitchYard, beans can also consume other services. Those references need to be injected. In this example the InventoryService is injected
@Inject @org.switchyard.component.bean.Reference private InventoryService _inventory;
Finally, all you need is the switchyard.xml configuration file where your Service, Components, Types and implementations are described.
<composite name="orders" > <component name="OrderService"> <implementation.bean class="org.switchyard.quickstarts.bean.service.OrderServiceBean"/> <service name="OrderService"> <interface.java interface="org.switchyard.quickstarts.bean.service.OrderService"/> </service> </component> </composite>
That was a very quick rundown. We've not touched the webservice endpoints, the WSDL and the Transformer configuration and implementation. Have a look at the SwitchYard tutorial which was published by mastertheboss and take the chance to read more about SY at the following links:
- SwitchYard Project Documentation
- SwitchYard Homepage
- Community Pages on JBoss.org
- SwitchYard is part of Fuse ServiceWorks, give it a try in a full fledged SOA Suite.
Published at DZone with permission of Markus Eisele , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.