Netflix / glisten

Ease of use Groovy library for building JVM applications with Amazon Simple Workflow (SWF)
Apache License 2.0
67 stars 31 forks source link

Spring integration #31

Closed bsideup closed 9 years ago

bsideup commented 9 years ago

Hi!

Can I get some docs how to integrate Glisten with Spring? For example, how to autowire some dependencies in workflow

Thanks!

claymccoy commented 9 years ago

It is impossible to inject the workflow because it's instantiation is outside of our control. It is constructed by the Flow framework. I agree that is a little frustrating, but you probably don't need to inject the workflow anyway. The workflow should just coordinate activities, and it is trivial to do DI (with whatever framework you want) on your activities because you do control their instantiation.

bsideup commented 9 years ago

Our workflow is complicated and spawn activities based on current database state. Since activities are flow-less we can't move this logic to them.

Btw, I found a way to use Glisten with Spring:

@Bean(destroyMethod = "shutdownNow")
public GenericWorkflowWorker genericWorkflowWorker(AmazonSimpleWorkflow amazonSimpleWorkflow, ApplicationContext applicationContext) throws IllegalAccessException, InstantiationException {
    GenericWorkflowWorker workflowWorker = new GenericWorkflowWorker(amazonSimpleWorkflow, domain, taskList);

    POJOWorkflowDefinitionFactoryFactory workflowDefinitionFactoryFactory = new POJOWorkflowDefinitionFactoryFactory() {

        @Override
        protected POJOWorkflowImplementationFactory getImplementationFactory(Class<?> workflowImplementationType, Class<?> workflowInterface, WorkflowType workflowType) {
            return new POJOWorkflowImplementationFactory() {

                @Override
                public Object newInstance(DecisionContext decisionContext) throws Exception {
                    return applicationContext.getBean(workflowInterface);
                }

                @Override
                public void deleteInstance(Object instance) {
                }
            };
        }
    };

    workflowDefinitionFactoryFactory.addWorkflowImplementationType(ClubWarProcessorWorkflowImpl.class);

    workflowWorker.setWorkflowDefinitionFactoryFactory(workflowDefinitionFactoryFactory);

    return workflowWorker;
}
claymccoy commented 9 years ago

Wow, I didn't know that was possible. Nice!

bsideup commented 9 years ago

Now I have Spring Java-only project with Glisten-based SWF workflow where only *WorkflowImpl file is in Groovy, everything else in pure Java. I can contribute an example of usage because I think this is a good case for Glisten and especially for projects where main language is Java:)

mooreds commented 9 years ago

@bsideup I would love to see that example if you can make it available.

fzakaria commented 9 years ago

There is the Flow Spring package as well that includes SpringWorkflowWorker, which I think does something similar. They also recommend setting the Workflow to a special scope they define.