Skip to content

Commit

Permalink
CosmosStoreClient = Connector + Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 3, 2021
1 parent 6f3c8a3 commit 011713c
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The `Unreleased` section name is replaced by the expected version of next releas

### Added

- `CosmosStore.CosmosStoreClient`: Merge of `CosmosStore.CosmosStoreConnector` and `CosmosStoreConnection` [#280](https://github.com/jet/equinox/pull/280)
- `CosmosStore.CosmosStoreConnector`: Uses the CosmosDB SDK 3.17 `CreateAndInitialize` to correctly connect and initialize a CosmosClient for an application [#279](https://github.com/jet/equinox/pull/279)

### Changed
Expand Down
7 changes: 4 additions & 3 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1825,15 +1825,16 @@ let outputLog = LoggerConfiguration().WriteTo.NLog().CreateLogger()
let gatewayLog =
outputLog.ForContext(Serilog.Core.Constants.SourceContextPropertyName, "Equinox")
let factory : Equinox.CosmosStore.CosmosStoreClientFactory =
CosmosStoreClientFactory(
let factory : Equinox.CosmosStore.CosmosClientFactory =
CosmosClientFactory(
requestTimeout = TimeSpan.FromSeconds 5.,
maxRetryAttemptsOnRateLimitedRequests = 1,
maxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds 3.)
// If storing in a single collection, one specifies the db and collection when using Connect()
// alternately use factory.CreateUnitialized, which defers that until the stream one is writing to becomes clear
let! client, connection = factory.Connect(Discovery.ConnectionString connectionString, "databaseName", "containerName")
let createCosmosClient containers = factory.Connect(Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), containers)
let! connection = CosmosStoreClient.Connect(createCosmosClient, "databaseName", "containerName")
let ctx = EventsContext(connection, gatewayLog)
Expand Down
8 changes: 4 additions & 4 deletions samples/Infrastructure/Storage.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ module Cosmos =
// NOTE: this is a big song and dance, don't blindly copy!
// - In normal usage, you typically connect to a single container only.
// - In hot-warm scenarios, the secondary/fallback container will frequently within the same account and hence can share a CosmosClient
// For these typical purposes, CosmosStoreConnector.Connect should be used to establish the Client and Connection, not custom wiring as we have here
// For these typical purposes, CosmosStoreClient.Connect should be used to establish the Client and Connection, not custom wiring as we have here
let createClient (a : Info) connectionString =
let clientFactory = CosmosStoreClientFactory(a.Timeout, a.Retries, a.MaxRetryWaitTime, mode=a.Mode)
let clientFactory = CosmosClientFactory(a.Timeout, a.Retries, a.MaxRetryWaitTime, mode=a.Mode)
clientFactory.CreateUninitialized(Discovery.ConnectionString connectionString)
let connect (log : ILogger) (a : Info) =
let (primaryClient, primaryDatabase, primaryContainer) as primary = createClient a a.Connection, a.Database, a.Container
Expand All @@ -114,9 +114,9 @@ module Cosmos =
let connection =
match connect log a with
| (client, databaseId, containerId), None ->
CosmosStoreConnection(client, databaseId, containerId)
CosmosStoreClient(client, databaseId, containerId)
| (client, databaseId, containerId), Some (client2, db2, cont2) ->
CosmosStoreConnection(client, databaseId, containerId, client2 = client2, databaseId2 = db2, containerId2 = cont2)
CosmosStoreClient(client, databaseId, containerId, client2 = client2, databaseId2 = db2, containerId2 = cont2)
log.Information("CosmosStore Max Events in Tip: {maxTipEvents}e {maxTipJsonLength}b Items in Query: {queryMaxItems}",
a.TipMaxEvents, a.TipMaxJsonLength, a.QueryMaxItems)
let context = CosmosStoreContext.Create(connection, queryMaxItems = a.QueryMaxItems, tipMaxEvents = a.TipMaxEvents, tipMaxJsonLength = a.TipMaxJsonLength)
Expand Down
9 changes: 4 additions & 5 deletions samples/Tutorial/AsAt.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ module Cosmos =
open Equinox.CosmosStore

let read key = System.Environment.GetEnvironmentVariable key |> Option.ofObj |> Option.get
let factory = CosmosStoreClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5., mode=Microsoft.Azure.Cosmos.ConnectionMode.Gateway)
let discovery, db, container = Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER"
let connector = CosmosStoreConnector(factory, Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"))
let client, connection = connector.Connect(read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(connection)
let factory = CosmosClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5., mode=Microsoft.Azure.Cosmos.ConnectionMode.Gateway)
let createCosmosClient containers = factory.Connect(Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), containers)
let storeClient = CosmosStoreClient.Connect(createCosmosClient, read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(storeClient)
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.) // OR CachingStrategy.NoCaching
let accessStrategy = AccessStrategy.Snapshot (Fold.isValid,Fold.snapshot)
let category = CosmosStoreCategory(context, Events.codec, Fold.fold, Fold.initial, cacheStrategy, accessStrategy)
Expand Down
10 changes: 5 additions & 5 deletions samples/Tutorial/Cosmos.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ module Store =
open Equinox.CosmosStore

let read key = System.Environment.GetEnvironmentVariable key |> Option.ofObj |> Option.get
let factory = Equinox.CosmosStore.CosmosStoreClientFactory(System.TimeSpan.FromSeconds 5., 2, System.TimeSpan.FromSeconds 5.)
let connector = CosmosStoreConnector(factory, Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"))
let client, connection = connector.Connect(read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let createContext () = CosmosStoreContext(connection)
let factory = Equinox.CosmosStore.CosmosClientFactory(System.TimeSpan.FromSeconds 5., 2, System.TimeSpan.FromSeconds 5.)
let createCosmosClient containers = factory.Connect(Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), containers)
let connect () = CosmosStoreClient.Connect(createCosmosClient, read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER")

let context = Store.createContext ()
let storeClient = Store.connect () |> Async.RunSynchronously
let context = Equinox.CosmosStore.CosmosStoreContext(storeClient)
let cache = Equinox.Cache(appName, 20)
let service = Favorites.Cosmos.create (context, cache)

Expand Down
9 changes: 4 additions & 5 deletions samples/Tutorial/FulfilmentCenter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ module Store =

let read key = Environment.GetEnvironmentVariable key |> Option.ofObj |> Option.get
let appName = "equinox-tutorial"
let factory = CosmosStoreClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5., mode=Microsoft.Azure.Cosmos.ConnectionMode.Gateway)
let discovery, db, container = Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER"
let connector = CosmosStoreConnector(factory, Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"))
let client, connection = connector.Connect(read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(connection)
let factory = CosmosClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5., mode=Microsoft.Azure.Cosmos.ConnectionMode.Gateway)
let createCosmosClient containers = factory.Connect(Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), containers)
let storeClient = CosmosStoreClient.Connect(createCosmosClient, read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(storeClient)
let cache = Equinox.Cache(appName, 20)
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.) // OR CachingStrategy.NoCaching

Expand Down
8 changes: 4 additions & 4 deletions samples/Tutorial/Todo.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ open Equinox.CosmosStore
module Store =

let read key = Environment.GetEnvironmentVariable key |> Option.ofObj |> Option.get
let factory = CosmosStoreClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5.)
let connector = CosmosStoreConnector(factory, Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"))
let client, connection = connector.Connect(read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(connection)
let factory = CosmosClientFactory(TimeSpan.FromSeconds 5., 2, TimeSpan.FromSeconds 5.)
let createCosmosClient containers = factory.Connect(Discovery.ConnectionString (read "EQUINOX_COSMOS_CONNECTION"), containers)
let storeClient = CosmosStoreClient.Connect(createCosmosClient, read "EQUINOX_COSMOS_DATABASE", read "EQUINOX_COSMOS_CONTAINER") |> Async.RunSynchronously
let context = CosmosStoreContext(storeClient)
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.)

module TodosCategory =
Expand Down
Loading

0 comments on commit 011713c

Please sign in to comment.