This document discusses workflow patterns and correlation in Neuron ESB. It describes the singleton pattern, which restricts workflow instances to one object to coordinate actions. It also covers correlated send/receive patterns using correlation IDs and sets to associate messages. Compensation is discussed as a way to undo completed work in non-transactional systems using compensable activities. The document provides examples of singleton, correlated send/receive, and compensation implementation and recommends hands-on practice through a correlated workflow lab.
2. Workflow Patterns and Correlation
• Understand how to use correlated workflows
• Understand how to use the message correlation scope
Goals
3. Workflow Patterns and Correlation
• Using singleton patterns with workflows
• Using correlation when sending and receiving messages
• Using the message correlation scope
• Using compensation
Lesson Plan
4. Workflow Patterns and Correlation
• It is a design pattern that restricts the instantiation of a class to one object
• It is useful when exactly one object is needed to coordinate actions across the system
• In workflow, this means that for a given set of messages, only one workflow instance will be
created
• Use cases:
• Aggregating messages for batch deliver – i.e. Collect Orders for FTP to partner
• Collecting data that is delivered across multiple messages – i.e. an order is delivered across multiple
files (header, line items, footer)
Singleton Pattern
5. Workflow Patterns and Correlation
Singleton Pattern
What’s required for a singleton?
• Create a “Correlated Workflow”
• In a loop:
• Receive Message
• Do something with the received
message
• Check condition
• Am I expecting a certain number of
files?
• Am I expecting a “terminating” file?
• Always put a time limit – avoid
“Zombies”
6. Workflow Patterns and Correlation
Correlation Sets
What is a Correlation Set?
• Identifies the message as being part of a
unique set
• Necessary for Neuron to associate messages
with one another
How else can you initialize a Correlation Set?
• Correlated Workflow
• Correlation Set Tab of the Workflow Endpoint
• Can use custom properties as well as aspects
of the message
• Message Correlation Scope
• Use this when there isn’t a one-way publish to
initialize the correlation set
• Define the Correlation Set on the Message
Correlation Scope
• Define a CorrelationID and set on the Receive
Activity Must be “correlationId”
7. Workflow Patterns and Correlation
• Long-running transactions require asynchronous communication with external systems
• How do you correlate a response that comes in 2 days later?
• What happens to the workflow instance while it’s waiting?
• Use cases:
• EDI (Send 850 via GEIS, partner receives 850 and send back an ACK the next day)
• Approvals – Send an email requiring a response
Correlated Send / Receive
8. Workflow Patterns and Correlation
What’s required for a correlated send/receive?
• Correlation ID – This is the value that is used for routing incoming messages to the correct instance of
the workflow. You must define this variable, but do not set it!
• Correlation Set – This defines the location of the value in the incoming message that will be used in
the Correlation ID. It’s easiest to use a message property!
• Publish Message Activity – Publishes the one-way request and initializes the correlation set
• Receive Message Activity – Participates in the correlation by creating an internal subscription for
message(s) that match the correlation set
Correlated Send / Receive
9. Workflow Correlation : Demo
Purpose:
To familiarize users with correlated workflows in the Neuron ESB Explorer
Objectives:
To acquaint users with how to create correlated workflows:
• Correlation Sets
• Correlating Send and Receive
10. Workflow Patterns and Correlation
Compensation
• What is compensation?
• The mechanism by which previously completed work can be
undone
• Why is it important?
• Not all systems are transactional!
• How do you do it?
• Compensable Activity
• See: https://msdn.microsoft.com/en-
us/library/system.activities.statements.compensableactivity(v=vs.110).a
spx
11. Workflow Patterns and Correlation : Lab
Purpose:
Learn how to create a a workflow which implements correlated send and receive.
Objectives:
• Create a workflow with correlated send and receive
• Test the correlated workflow at design time
12. Workflow Patterns and Correlation
Review
• Correlated workflows allow Neuron ESB to implement a singleton pattern
• Correlated IDs and Correlation Sets are necessary for implementing correlation
• When systems are not transactional they can be used in a compensation block
Editor's Notes
The goals of this lesson are to provide users with an understanding of how to use correlated workflows and the message correlation scope.
This lesson has been broken down into four sections to make the information presented easier to understand. The sections that we will be covering are
Using singleton patterns with workflows
Using correlation when sending and receiving messages
Using the message correlation scope
Using compensation
The singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system. In workflows this means that for a given set of messages, only one workflow instance will be created. This is extremely useful in cases such as aggregating messages for batch deliver or collecting data that is delivered across multiple messages such as an order delivered from multiple files.
In order to create a singleton pattern in a workflow definition you need to create a correlated workflow, as these are the only workflow types that support the singleton pattern. Inside the workflow you would need to create a loop, usually a while loop. Using a while loop allows you to determine when to stop listening for messages. Are you expecting a certain number of messages? Is there some sort of message that indicates it is the last message in the set? Regardless of what method you use to determine the end of the expected messages, you should always encapsulate your loop in a timeout activity. This will avoid encountering zombie workflows should the final message not come through. Inside of the loop you will need to receive the message and then do something with that message such as add it to collection so the next message through does not overwrite it.
So how does Neuron ESB know which messages goes to which workflow? Neuron ESB uses parts of the message or custom properties to indicate the unique identifier that tells the system what set of messages a message belongs to. This identifier is called the correlation id. Once the correlation id is found, Neuron ESB puts that value in the correlation set for the workflow endpoint. Each time a new message comes in, Neuron compares the messages correlation id with the correlation set of the running workflows. If a match is found, the message is handed off to the workflow. If not, then a new workflow is instantiated with the correlation set as the value of the correlation id.
The correlation set of a correlated workflow is set on the Correlation Set tab of the workflow endpoint. This tab is only active if the workflow definition associated with the endpoint is a correlated workflow definition. Correlation sets also play a part in the message correlation scope, which we will discuss later in this presentation. However, it is important to note that the message correlation scope must be used in conjunction with a receive activity in order to get messages from the bus for the correlation set associated with it.
Correlated send and receive is used when a long running transaction requires asynchronous communication with external systems. For example in a case where an approval is needed before allowing the workflow to continue processing, think loan types situations, it may take a day or more before that approval comes back. This is far outside the normal time period for a request reply scenario, so the correlated send and receive would be used to correlate the response back the the original requester without having to worry about a request reply timeout. While the workflow is waiting, the workflow unloads itself until it is informed that a message has been received.
In order to perform a correlated send and receive you will need
Correlation ID – This is the value that is used for routing incoming messages to the correct instance of the workflow. You must define this variable, but do not set it!
Correlation Set – This defines the location of the value in the incoming message that will be used in the Correlation ID. It’s easiest to use a message property!
Publish Message Activity – Publishes the one-way request and initializes the correlation set
Receive Message Activity – Participates in the correlation by creating an internal subscription for message(s) that match the correlation set
Compensation is the ability to undo the work performed by a series of activities, which together define an eventually consistent operation, if one or more of the steps fail. This is important if you are attempting to use transactions with a system that does not support them. The CompensableActivity activity provides this functionality for you, allowing you to create a series of steps that tell the system how to undo what was done in a system the does not support transactions.