Amazon SWF was launched today. How best to consume it with Java / PHP / etc. ?
The current SDK support doesn't appear to include it. I know it's new, but does anyone have any good resources on how to consume it, or what changes I'd need to implement in the any of the following SDK's to get going right away?
Personally, my interest is on the Java & PHP SDK's...
Updated releases are visible at: http://aws.amazon.com/releasenotes Thanks Bjorn!
Did you check the updated SDKs today? There was a new release about 10 hours ago (1.4.3 for .NET at least, released on February 21, 2012).
http://aws.amazon.com/releasenotes/.NET/5023081835314406
For the brave souls that read this: Most of the stuff still applies. To make it work with Java 1.8, you need to use the following aspect library with AspectJ:
For a full sample look at: https://github.com/mirceal/swf-flow-java18-sample
I'm using Amazon Simple Workflow Service (SWF) to implement asynchronous business processing using the AWS Flow Framework. It was important to me to have my development build setup using Maven, so that I could easily build from my IDE of choice (IntelliJ IDEA) as well as automate my test builds for continuous integration and production builds for release and deploy.
Most of my time was spent trying to get the auto-generated proxy classes created using AspectJ. This was initially a problem for me in Eclipse as I was using version 3.7 (Indigo) and even after following both the load-time and compile-time weaving instructions in the Setting up the Development Environment documentation I was unable to successfully get the classes blown out. On a hunch I remembered that the documentation says they used Eclipse 3.6 (Helios), so I downloaded this specific version of Eclipse and retried using the load-time weaving approach and it worked like a champ. Looking at the Eclipse logs between these two versions I was able to see that Eclipse 3.7 is missing a dependency for
log4j
andfreemarker
. I didn't bother going too far down the road to troubleshoot this further with Eclipse as I'm more of an IntelliJ IDEA user, but I'm sure that it's most definitely possible to get Eclipse working properly.My next effort was to get an IntelliJ IDEA Maven project up and running with the minimum amount of information in my
pom.xml
to enable the auto-generation of the proxy classes. The clue was the last paragraph of the instructions for load-time weaving in the Setting up the Development Environment documentation, which states:Unless I'm mistaken, the research I've done to date indicates that the
aspectj-maven-plugin
doesn't not currently support load-time weaving. Breaking away from doing load-time weaving and utilizing anaop.xml
file in conjunction withaspectjweaver
running as a Java agent, I moved to compile-time weaving supported by this plugin. I can't help but think that when I installed the AWS SDK for Java support directly in Eclipse that it in turn baked in the support found in theaws-java-sdk-flow-build-tools-1.3.3.jar
dependency. Taking the aforementioned clue, I was finally able to get the proxy classes blowing out by including a dependency foraws-java-sdk-flow-build-tools-1.3.3.jar
in mypom.xml
after installing this JAR into my local Maven repository. The rest of this entry outlines the steps taken to make this all happen.IntelliJ IDEA Project Creation
pom.xml
.AWS SDK for Java
In order to reference the necessary types for developing workflows and activities, you will need to download the AWS SDK for Java. It is recommended that you use Maven to include a
dependency
for this library for your project and build, but you should still download this library in order to get theaws-java-sdk-flow-build-tools
library which can be found under thelib
directory.SWF Flow Build Tools
The AWS SDK for Java download includes a
aws-java-sdk-flow-build-tools-<version>.jar
JAR under thelib
directory. In order to allow the inclusion of a Mavendependency
for this library, you'll need to install the JAR into your local Maven repository. You can achieve this by running the following from thelib
directory of the AWS SDK download:NOTE: Be sure to replace the tokens in the above command with the appropriate version found in your AWS SDK download.
Maven
Your
pom.xml
file should include the followingdependencies
. I've included the version numbers I'm using in case you run into breaking changes using different versions:Your
pom.xml
file should also include the followingplugin
. I'm using source include patterns that following a packaging and interface naming convention I use in my code, though you don't necessarily need to do things this way:Once you've include the
plugin
listed above and have at least run a Mavencompile
, you should notice anaspectj
node appear under thePlugins
node within the Maven Projects tool window in IntelliJ IDEA. You can also optional add or tweak the elements of theconfiguration
section of theaspectj-maven-plugin
plugin if you desire. The various supported settings can be found in theaspectj:compile
goal documentation found here. I've haven't tweaked my plugin configuration yet to ensure that the.java
files are generated in the proper location under my source directory, though I'm sure this is quite doable.External Libraries
Once you've include the set of
dependencies
listed above and have at least run a Mavencompile
, you should notice at minimum the following set of dependencies listed under the External Libraries node within the Project tool window in IntelliJ IDEA:Example pom.xml
Defining Workflows
To define a workflow you must create a Java interface that meets the following criteria:
The following is an example workflow interface named
MyWorkflow
, and would be contained a file namedMyWorkflow.java
, located under the source directorysrc/main/java
, and under the package directory structurecom/some/package/workflow
. I haven't included the@WorkflowRegistrationOptions
annotation or other bells and whistles as these aren't required and are dependent on your particular needs:Defining Activities
To define activities you must create a Java interface that meets the following criteria:
The following is an example activities interface named
MyActivities
, and would be contained in a file namedMyActivities.java
, located under the source directorysrc/main/java
, and under the package directory structurecom/some/package/workflow/activities
. I haven't included the@ActivityRegistrationOptions
annotation or other bells and whistles as these aren't required and are dependent on your particular needs:Building
In order to ensure that the build process is the same during everyday development as well as for non-development environments (e.g. test, production, etc.), you should run builds in your development tool of choice through Maven. Various aspects have been included in the
aws-java-sdk
andaws-java-sdk-flow-build-tools
JARs which are weaved into your workflows and activities, and theaws-java-sdk-flow-build-tools
JAR includes the necessary mechanism to auto-generate the required proxy classes to execute workflows and activities. In order to ensure that you're working with the latest generated proxy classes, you should take care to clean the generated artifacts before a build in order to throw away unneeded and/or old classes. This can be achieved by running the following command or equivalent in your development tool of choice:If you keep the
showWeaveInfo
configuration option enabled in theaspectj-maven-plugin
plugin, you should see something like the following snippet in your build output, albeit there are only have a few lines of output here due to only having a single workflow and single activities for this run:Auto-Generated Proxies
Once you've compiled your workflows and activities you should find the follow set of auto-generated proxy classes have been created. These proxies are to be used within your workflows to call upon your various activities, execute child workflows within other workflows, and also to execute workflows at a top level. NOTE: The strings "Workflow" and "Activities" in the following bullets would actually be the name of your actual workflow and activities interfaces respectively, and you should see the following set of classes created for each of your defined workflow and activities interfaces:
I'm also including some background information to help clarify the type of development environment I'm working on and tools I'm using for day to day coding.
OS
Java
Maven
IntelliJ IDEA (Community Edition)
Here is a more recent answer that works for Java8 (JDK8) and compile time weaving.
The problem is that the maven compiler can perform annotation processing. If its turned on and aspectj, you will try to double create the same classes. its better to leave the maven compiler to process the annotations (generate the workflow/activity classes) since aspectJ needs them created so it can then do its weaving (@Retry @Async)
Several years later, this thread helped me a lot to make AWS SWF Flow work with Maven. However, some aspects are not working out of the box with this approach. I have written an article to concentrate all my findings. PS: would love some tips to make Java 1.8 work as well with this.
I have managed to make JAVA8 / AWS SDK 1.9.x work with Maven and Eclipse following this remarkable examples pedropaulovc/aws-flow-maven-eclipse-samples and tweaking the pom.xml, including the brave Mircea suggestion and other reworks.
you can find the resulting working pom.xml here
Note that i had to add to the aspectj plugin aspect libraries also the updated flow-build-tools, otherwise, the Activity and Workflow impl version number annotations do not work properly
Hope this could be helpful!