Skip to content

Instantly share code, notes, and snippets.

@jcdickinson
Created February 14, 2011 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcdickinson/826025 to your computer and use it in GitHub Desktop.
Save jcdickinson/826025 to your computer and use it in GitHub Desktop.

SQL Tables

Subscriber

ID BIGINT PRIMARY IDENTITY, SoapEndpoint NVARCHAR(256), Escalation INT, Other Metadata

Message

ID UNIQUEIDENTIFIER PRIMARY, Payload VARBINARY(MAX), Other Metadata

MessageDelivery

SubscriberID UNIQUEIDENTIFIER PRIMARY, MessageID UNIQUEIDENTIFIER PRIMARY, Retries INT = 0, IsDelivered BIT = 0,

Operations

CreateSubscriber

  • Add subscriber to Subscriber table.

DeleteSubscriber

  • Remove subscriber from Subscriber table.

BeforeDeliver

VB.Net:

  • Create GUID (=mid) SQL:
  • Insert message into Message table (ID = mid)
  • Foreach Subscriber (sid=ID), insert into MessageDelivery table (SubscriberID = sid, MessageID = mid)
  • SELECT MD.SubscriberID, MD.MessageID, MD.Retries, M.Payload, S.SoapEndpoint, S.Escalation From MessageDelivery AS MD JOIN Message AS M ON MD.MessageID = M.ID JOIN Subscriber AS S ON MD.SubscriberID = S.ID WHERE MD.MessageID = @mid AND MD.SubscriberID = @sid AND M.IsDelivered = 0;

Deliver

VB.Net:

  • PAUSE (not stop/reset) redeliver tick timer
  • For each row from BeforeDeliver -- Call SOAP endpoint with message payload (this will probably be 'anonymous' XML - i.e. WebService with XmlDocument as the only parameter). -- If it fails increase Retries, otherwise set IsDelivered to 1. -- Check to see if Retries matches Escalation, if it does notify admin.
  • Resume deliver tick timer

ReDeliver Tick (every say 30s, non-overlapping)

SQL:

SELECT MD.SubscriberID, MD.MessageID, MD.Retries, M.Payload, S.SoapEndpoint, S.Escalation From MessageDelivery AS MD JOIN Message AS M ON MD.MessageID = M.ID JOIN Subscriber AS S ON MD.SubscriberID = S.ID WHERE M.IsDelivered = 0 AND M.Retries < S.Escalation VB.Net:

  • For each row returned -- Call SOAP endpoint with message payload (this will probably be 'anonymous' XML - i.e. WebService with XmlDocument as the only parameter). -- If it fails increase Retries, otherwise set IsDelivered to 1. -- Check to see if Retries matches Escalation, if it does notify admin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment