Difference between revisions of "ITrack/MySQL Message Framework"

From ISoft Wiki
Jump to navigationJump to search
(New page: The MySQL Message Framework is used to create a connection to a message repository. The message repository allows the calling code to create and receive messages from other processes. ==...)
 
Line 2: Line 2:


== General ==
== General ==
The MySQL Message Framework requires the following:
* The ability to connect to an external MySQL server.
The MySQL Message Framework is an ISoft internal tool; it is used at developer discretion and cannot be added on-the-fly via extensions.


== Usage ==
== Usage ==
Add the MySQL Message Framework project to your workspace and its .lib file included in the project that you wish to use it in.
Add this include line to your source: #include "../../Libraries/include/libITMySQLMessageFramework.h"
Read [[ITrack/MySQL_Message_Framework#Code|Code]] to see how to use each instance.


== Code ==
== Code ==
Each message pipe requires an object.  The object is persistent, and should be put into a thread that has a sleep cycle of some variety.
=== Creating a new Message Framework object ===
Create a new ITMySQLMessageFramework object:
* ITMySQLMessageFramework* itMessageFramework = new ITMySQLMessageFramework(<active connection handle to the message repository>, <service type enum>, <service id unique int>, <service handle if one already exists>, <one or more flags for type> OR ITMySQLMessageFramework::GetStandardFlags())
* Call IsHeartbeatActive() to make sure your heartbeat is available
* Call IsMessagePipeActive() to make sure your message pipe is available (if you don't have a service handle, it won't be)
=== Using Heartbeat functionality ===
* Whenever you deem necessary, call itMessageFramework->TriggerHeartbeat(<optional status>)
* If it's your first heartbeat, you can now call itMessageFramework->GetHandle() to get the service's handle.  This is necessary for posting/receiving messages
=== Using Message Pipe functionality ===
If you have a new handle and the pipe isn't connected, call:
* itMessageFramework->InitMessagePipe(itMessageFramework->GetHandle());
* Check IsMessagePipeActive() to make sure it worked
To check for new messages given to your process, call:
* itMessageFramework->PumpMessages()
* while (itMessageFramework->GetNextMessage(message)) {...} will give you each message you received
==== Submitting a message ====
* Create a new ITMySQLMessage object
* message.SetRecipient(<recipient handle>) if you know the recipient.  Leave blank if you don't
* message.SetName(<message type name>) if you didn't provide it in the constructor
* message.AddInputData(...) and message.AddOutputData(...) to attach your message data
* itMessageFramework->SubmitMessage(message);
==== Responding to a message ====
* Use the message you got from itMessageFramework->GetNextMessage(message)
* message.SetName(<message response type name>) if you want to change the message type
* message.AddOutputData(...) to add your response data if any
* itMessageFramework->SubmitResponse(message)


=== Caveats ===
=== Caveats ===
Errors that occur will most likely be ITSQLError objects that get thrown.


[[Category:ITrack/Code]]
[[Category:ITrack/Code]]

Revision as of 13:30, 8 April 2010

The MySQL Message Framework is used to create a connection to a message repository. The message repository allows the calling code to create and receive messages from other processes.

General

The MySQL Message Framework requires the following:

  • The ability to connect to an external MySQL server.

The MySQL Message Framework is an ISoft internal tool; it is used at developer discretion and cannot be added on-the-fly via extensions.

Usage

Add the MySQL Message Framework project to your workspace and its .lib file included in the project that you wish to use it in. Add this include line to your source: #include "../../Libraries/include/libITMySQLMessageFramework.h"

Read Code to see how to use each instance.

Code

Each message pipe requires an object. The object is persistent, and should be put into a thread that has a sleep cycle of some variety.

Creating a new Message Framework object

Create a new ITMySQLMessageFramework object:

  • ITMySQLMessageFramework* itMessageFramework = new ITMySQLMessageFramework(<active connection handle to the message repository>, <service type enum>, <service id unique int>, <service handle if one already exists>, <one or more flags for type> OR ITMySQLMessageFramework::GetStandardFlags())
  • Call IsHeartbeatActive() to make sure your heartbeat is available
  • Call IsMessagePipeActive() to make sure your message pipe is available (if you don't have a service handle, it won't be)

Using Heartbeat functionality

  • Whenever you deem necessary, call itMessageFramework->TriggerHeartbeat(<optional status>)
  • If it's your first heartbeat, you can now call itMessageFramework->GetHandle() to get the service's handle. This is necessary for posting/receiving messages

Using Message Pipe functionality

If you have a new handle and the pipe isn't connected, call:

  • itMessageFramework->InitMessagePipe(itMessageFramework->GetHandle());
  • Check IsMessagePipeActive() to make sure it worked

To check for new messages given to your process, call:

  • itMessageFramework->PumpMessages()
  • while (itMessageFramework->GetNextMessage(message)) {...} will give you each message you received

Submitting a message

  • Create a new ITMySQLMessage object
  • message.SetRecipient(<recipient handle>) if you know the recipient. Leave blank if you don't
  • message.SetName(<message type name>) if you didn't provide it in the constructor
  • message.AddInputData(...) and message.AddOutputData(...) to attach your message data
  • itMessageFramework->SubmitMessage(message);

Responding to a message

  • Use the message you got from itMessageFramework->GetNextMessage(message)
  • message.SetName(<message response type name>) if you want to change the message type
  • message.AddOutputData(...) to add your response data if any
  • itMessageFramework->SubmitResponse(message)

Caveats

Errors that occur will most likely be ITSQLError objects that get thrown.