-
Notifications
You must be signed in to change notification settings - Fork 14
AtomEventsOnAzure
AtomEventsOnAzure is one of AtomEventStore's built-in storage options. It uses Microsoft Azure BLOB storage to store Atom Feed documents.
A single instance of AtomEventsOnAzure can handle an arbitrary number of event streams; the size limit is determined by Microsoft Azure BLOB storage.
Note: Since AtomEventsOnAzure depends on Microsoft Azure-specific libraries, it's not included in the core distribution of AtomEventStore, but rather in the AtomEventStore.AzureBlob NuGet package.
Each event stream is identified with an ID (a GUID), so each event stream is persisted in a 'sub-container' named after that ID. Azure BLOB storage uses URL segments to model 'sub-containers'. In the following discussion, this feature will be treated as though these 'sub-containers' constitute a real hierarchy, because in this context, it's enough that the client views the BLOBs as though they are organised in this way.
In each sub-container is an index document, which has the same name as the sub-container itself, and one or more Atom Feed page documents. This makes document access times constant, because a client accessing a particular event stream already knows the ID of that event stream, which means that it already knows the name of the index document it needs to read.
An example container structure might look like this:
040e5521-9d13-4742-8cef-69452f925124/040e5521-9d13-4742-8cef-69452f925124.xml
040e5521-9d13-4742-8cef-69452f925124/04d7b2c7-3560-40c3-beaf-a982872fba43.xml
2aeef422-623f-4a7c-9d13-1145a366c8ca/2aeef422-623f-4a7c-9d13-1145a366c8ca.xml
2aeef422-623f-4a7c-9d13-1145a366c8ca/a9b1de32-0faa-4d58-867f-c425abe7de36.xml
e475ed17-31dc-4030-95d2-97ee29ee6ef6/1fe50e0c-f040-47e2-b6ec-3ad6e8ef1780.xml
e475ed17-31dc-4030-95d2-97ee29ee6ef6/e475ed17-31dc-4030-95d2-97ee29ee6ef6.xml
e475ed17-31dc-4030-95d2-97ee29ee6ef6/e9a3256a-74b4-4853-a2bd-8cc61ac8cc1b.xml
e475ed17-31dc-4030-95d2-97ee29ee6ef6/f134bba9-eeda-4c60-8dc0-fa3b6e3f22a9.xml
The first sub-container is named 040e5521-9d13-4742-8cef-69452f925124, which means that it corresponds to the event stream with the ID 040e5521-9d13-4742-8cef-69452f925124. In that sub-container you can see two files. One of the files has the same name as the directory (040e5521-9d13-4742-8cef-69452f925124.xml); this is the index file of the event stream. It may look like this:
<feed xmlns="http://www.w3.org/2005/Atom">
<id>urn:uuid:040e5521-9d13-4742-8cef-69452f925124</id>
<title type="text">Index of event stream 040e5521-9d13-4742-8cef-69452f925124</title>
<updated>2014-07-31T10:31:10.6665499+00:00</updated>
<author>
<name>Grean</name>
</author>
<link href="040e5521-9d13-4742-8cef-69452f925124/040e5521-9d13-4742-8cef-69452f925124"
rel="self"/>
<link href="040e5521-9d13-4742-8cef-69452f925124/04d7b2c7-3560-40c3-beaf-a982872fba43"
rel="first"/>
<link href="040e5521-9d13-4742-8cef-69452f925124/04d7b2c7-3560-40c3-beaf-a982872fba43"
rel="last"/>
</feed>
Notice that in this example, the index points to the other file (040e5521-9d13-4742-8cef-69452f925124.xml) as both the first and last page in the Atom Feed.
In one of the other sub-directories (e475ed17-31dc-4030-95d2-97ee29ee6ef6) you can see that there are multiple Atom Feed page files (three, to be exact) besides the index file (e475ed17-31dc-4030-95d2-97ee29ee6ef6.xml). This happens when there are more events in that particular event stream than fits in each page. The page size is a configurable value.
In order to use the AtomEventsOnAzure
class, you must pass it a CloudBlobContainer
instance representing the root container:
var storageConnectionString =
CloudConfigurationManager.GetSetting("StorageConnectionString");
var storageAccount =
CloudStorageAccount.Parse(storageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("events");
container.CreateIfNotExists();
var storage = new AtomEventsOnAzure(container);
This example first demonstrates how to build a CloudBlobContainer
using the Microsoft Azure SDK from the WindowsAzure.Storage NuGet package. Only the final line of code in this example uses AtomEventStore.
Since AtomEventsOnAzure
implements IAtomEventStorage, the storage
variable can be passed to writers and readers of event streams.