On This Page

Next

Publish.exe

Previous

Task Manager

Direct Message


Out of the box, Task Manager fires a business rule with an action of Carrier Message.

The business rule action message content looks like:

type=RunTaskSet
caseId=[Object ID]
taskSetName=[Task Set Name]

Rulemanager turns this into an actual message, and sends it to Carrier. Out of the box, Carrier only knows how to process these messages with a type of RunTaskSet.

This example walks through how to add a custom type, allowing Carrier to perform a custom action, completely independent of Task Manager.

Specifically, it will show how to add a type of GetStockQuote, that will call a web service to get a stock quote. Carrier will simply log the stock quote returned from the service.

Our new custom message will look like:


type=GetStockQuote
symbol=GOOG

The code for this example is located in src/Dovetail.TaskManagerExamples/MessageExample.

Create the Message

We'll start by defining the message that we want to directly consume:


	public class GetStockQuote
	{
		public string Symbol { get; set; }
	}

This message will be constructed after receiving the initial payload from Rule Manager. Properties are assigned through simple databinding.

Dovetail Admin

We'll create a new business rule that sends this new message type to Carrier.

Using Dovetail Admin, create a new business rule with the following properties:

Attribute Value
Object Type Case
Rule Name/Description Testing custom carrier messages
Start Events Log Note
Cancel Events None
Conditions Object ID = 12345 (set this to be an ID of one of your test cases)
Action Title Get Stock Quote
Create Activity Log Entry true (checked)
Who to Notify no one (leave empty)
Start Action 0 minutes
From Event Creation
Using Elapsed Time
Repeat Never
Message Type Carrier Message
Message type=GetStockQuote
symbol=GOOG

Map the Message

Messages must be mapped so that Carrier understands which message type we're referring to. We can do this simply be creating a subcase of the MessageTypeRegistry class:


	public class StockMessages : MessageTypeRegistry
	{
		public StockMessages()
		{
			Type("GetStockQuote").MapsTo<GetStockQuote>();
		}
	}

All derivatives of MessageTypeRegistry are automatically picked up.

Create a Consumer

We need to create a consumer for our new message. We can do this by implementing the Consumes<T>.All interface.

Let's look at the GetStockQuoteConsumer:


	public class GetStockQuoteConsumer : Consumes<GetStockQuote>.All
	{
		private readonly IStockQuoteService _quotes;
		private readonly ILogger _logger;

		public GetStockQuoteConsumer(IStockQuoteService quotes, ILogger logger)
		{
			_quotes = quotes;
			_logger = logger;
		}

		public void Consume(GetStockQuote message)
		{
			var quote = _quotes.FindBySymbol(message.Symbol);
			_logger.LogDebug("{0} ({1}) is currently at {2}", quote.Name, quote.Symbol, quote.Price);
		}
	}

We have the freedom to do any logic we want within a consumer. However, because we're not leveraging the Task Manager runtime, we have no context for a Case. We only have the data that was passed directly from Rule Manager.

Force the Business Rule to fire

Using Dovetail Agent

  • Open case 12345 (or whatever case you used in the business rule condition)
  • Log a note to the case
  • Refresh page
  • History menu - Show Details
  • You should see a new history item of Rule Action of Action Get Stock Quote of rule Testing custom carrier messages fired

Review Rulemanager logs

  • Open the Dovetail Rulemanager log file (typically C:\Program Files\Dovetail Software\Rule Manager\logs\RuleManager.log)
  • You should see a log entry that looks like
FChoice.RuleManager.Carrier.MessagePublisher - (null) Publishing type=GetStockQuote
symbol=GOOG to msmq://localhost/dovetail.carrier

Review Carrier logs

  • Open the Dovetail Carrier log file (typically C:\Program Files\Dovetail Software\Carrier\carrierservice\logs\Dovetail.Carrier.Service.log)
  • You should see a log entry that looks like
Dovetail.Carrier.Core.RuleManager.RuleManagerConsumer - (null) Carrier message received: type=GetStockQuote
symbol=GOOG

You should see a log entry that looks like

Dovetail.TaskManagerExamples - (null) Alphabet, Inc. (GOOG) is currently at 127.898